|No such thing as a small change|
[Raku] Arcane treatment of doubles and rationalsby syphilis (Bishop)
|on Apr 03, 2021 at 11:38 UTC||Need Help??|
syphilis has asked for the wisdom of the Perl Monks concerning the following question:
I ran the following script with raku:
I was surprised that it output:
However, I think I understand what's happening.
I had thought that when raku compared a double with a rational, it would convert the double to its exact rational value, and then compare the 2 rationals.
Instead it apparently converts the rational to a double (rounding if necessary), and then compares the 2 doubles.
I can see some sense in performing the comparison in the way they've chosen:
1) It's probably much cheaper to convert a rational to a double than vice-versa;
2) If the rounded rational is equivalent to the double then, under certain circumstances, you might be happy enough to think of the 2 values as being equivalent.
Doing it that way might be a useful comparison to be making, but I don't think it's a comparison that the numeric comparison operators (==, <, >, etc.) should be performing.
Anyway - the first of my questions (and there probably will be more):
Is there a way to get raku to explicitly display the fact that the (double precision) values held by $d_1 and $d_2 are exactly equivalent to the rational value 3602879701896397/36028797018963968 ?