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

You are right about bignum. Your bigrat example, though, doesn't work. One needs
perl -Mbigrat -le 'print 20/1 + 1/10'
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^4: floating point addition
by morgon (Priest) on Jan 12, 2015 at 20:15 UTC
    perl -Mbigrat -e ' printf "%20.17f\n", 20/1+1/10;' 20.10000000000000142 perl -Mbigrat -e ' printf "%20.17f\n", 201/10;' 20.10000000000000142
    Does not seem to work either - I don't know why not...
      Because %f converts the Math::BigRat object to "a floating-point number, in fixed decimal notation" (sprintf).
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        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?