pradosoft / prado

Prado - Component Framework for PHP
Other
186 stars 70 forks source link

#904 TRational/TURational unit classes Prado\Util\Math #934

Closed belisoful closed 1 year ago

belisoful commented 1 year ago

The Mathematical "rational" is an integer numerator divided by an integer denominator. This is the class providing the functionality around reading, computing, and outputting the rational.

The format for the Rational is, eg, "21/13" where 21 is the numerator and 13 is the denominator.

The unsigned rational is bound to 0..4294967295; where as the regular rational is signed and bound to [-2147483648..2147483647].

A Rational is found in EXIF and is common in its GPS "directory". It is found there as two 32 bit integers.

The star method of this class is the Continued Fraction computation to generate the integer numerator and integer denominator from a float, to a specific tolerance.

Updated TBitHelper with specific max, min, unsigned max, and mask for 32 bit and 64 bit integers, when the values are needed and not just the system values.

belisoful commented 1 year ago

Should the __invoke be kept or removed? I'm on the fence. I like that it accepts tolerance. The array access to Value (get and set, but without tolerance) with "[null]" is icing on the cake.

ctrlaltca commented 1 year ago

LGTM; even with the invoke

belisoful commented 1 year ago

I was dreaming about it this morning: Putting a TRational as an event handler because it's invokable.

lol. That's the only thing about invokable that makes me pause about having TRational being invokable like that. is it a good hack?

The invokable was implemented before access to the Rational Value as a [null] array accessor, and I like the array accessor much better than invokable (due to the implications of being invokable).

After my cup of coffee, I'm thinking of removing it. Let me do that, and it'll be acceptable as a merge.

My thinking of invokables is that their utility is more specific than this use.