Moritz Lenz wrote: >> Given the above, if one wants to construct a full-precision rational >> value in terms of 3 Int values analogous to a mantissa and radix and >> exponent, what is the best way to write it in Perl 6? >> >> For example, say I want the following expression to result in a FatRat >> because presumably that's the only type which will represent the result >> value exactly: >> >> 45207196 * 10 ** -37 >> >> How should that be spelled out in terms of 3 integers? > > why 3?
Because three attributes let you define them all as the same kind of int, instead of one having twice as many bits in it as the other: has int128 $whole, int128 $numerator, int128 $denominator vs. has int256 $numerator, int128 $denominator This matters when you reach the upper end of the low-level integer types, such that there is no longer an available integer type that has twice as many bits as the denominator type. But as you say, this is an implementation detail. The important thing for the Spec to note is that user expectations require Rational types to be able to handle a whole number part that's at least as large as the denominator part. Right now, the spec is addressing this in terms of implementation details: it assumes that a Rational will store exactly two numbers, representing the numerator and the denominator, and that the numerator must have twice as much storage space reserved for it as the denominator has. Why twice as much? So that no matter how large the denominator is, the numerator will be large enough to store a whole number part that's at least as large. The doubled bits isn't an end to itself, but merely a means to a more fundamental end. -- Jonathan "Dataweaver" Lang