Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Floating point issue

by Laurent_R (Canon)
on Aug 14, 2016 at 08:14 UTC ( [id://1169741]=note: print w/replies, xml ) Need Help??


in reply to Re: Floating point issue
in thread Floating point issue

A more accurate alternative might be to use integer arithmetic:
$ perl -E '$c = -71123456; for my $i (0..19) {say $c/1000000; $c += 10 +000}' -71.123456 -71.113456 -71.103456 -71.093456 -71.083456 -71.073456 -71.063456 -71.053456 -71.043456 -71.033456 -71.023456 -71.013456 -71.003456 -70.993456 -70.983456 -70.973456 -70.963456 -70.953456 -70.943456 -70.933456
You might also consider using the arbitrary big rational number module (Math::BigRat) or possibly the big float module (Math::BigFloat).

Math::BigRat is accurate because it basically does integer arithmetic under the hood.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-24 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found