in reply to Re^5: floating point addition
in thread floating point addition

But this remains strange to me:
perl -e 'print 201/10 == 20.10000000000000000 ? "eq" : "ne"' eq perl -Mbigrat -e 'print 201/10 == 20.10000000000000000 ? "eq" : "ne"' eq perl -e 'print 201/10 == 20.10000000000000142 ? "eq" : "ne"' eq perl -Mbigrat -e 'print 201/10 == 20.10000000000000142 ? "eq" : "ne" +' ne
The last two cases is where one can see the difference that bigrat makes, but should the comparison in the second case not yield false?

Replies are listed 'Best First'.
Re^7: floating point addition
by choroba (Cardinal) on Jan 13, 2015 at 08:39 UTC
    There's no 20.10000000000000142 under bigrat:
    $ perl -MO=Deparse -Mbigrat -le '$x = 201/10; $y = 20.1000000000000014 +2; print join " ", $x, $y, $x == $y ? "eq" : "ne"' BEGIN { $/ = "\n"; $\ = "\n"; } use bigrat; BEGIN { $^H{'float'} = q(CODE(0x6003db168)); $^H{'integer'} = q(CODE(0x600495668)); $^H{'binary'} = q(CODE(0x6004a8d28)); $^H{'bigrat'} = q(1); } $x = {_d => [10], _n => [201], sign => '+'}; $y = {_e => [17], _es => '-', _m => ['000000142', '010000000', '2'], s +ign => '+'}; print join(' ', $x, $y, $x == $y ? 'eq' : 'ne'); -e syntax OK
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ