Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: floating point addition

by choroba (Cardinal)
on Jan 12, 2015 at 18:09 UTC ( [id://1112973]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1112973]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-19 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found