# New Ticket Created by Zefram # Please include the string: [perl #128828] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=128828 >
> my $a = 2476979795053773e0 * (2e0**-51) 1.1 > ($a * (2e0**51)).Int 2476979795053773 > ($a * (2e0**51)) % 1e0 0 > $a.FatRat.perl FatRat.new(11, 10) The Num->FatRat conversion is being performed inexactly. Every finite Num value is in fact rational, and therefore exactly representable as a FatRat, so I would expect the coercion to preserve the value exactly. It should come out as FatRat.new(2476979795053773, 2251799813685248). Not only is 11/10 not the exact value of this Num, it's not the exact value of any Num, because the floating point format can only represent values whose denominators are powers of two. The same considerations would not in general apply to the .Rat coercion. Because the Rat type is intended to have a limited range of denominators, it cannot exactly represent all Num values. However, I believe the denominator in this particular case, 2**51, is in the intended range. So in this case $a.Rat also ought to be exact, but actually it also isn't. Note that in the above there is no rounding in the decimal->float conversion: the large integer value is less than 2**52, and so fits into a float with a bit to spare. There is also no rounding in the power-of-two or in the multiplication, which just changes the exponent of the float. So the Num $a exactly represents the value that is suggested by the way it was computed. The .Int and %1 operations illustrate the exact value. -zefram