Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

adding numbers and floating point errors

by smeenz (Sexton)
on Nov 22, 2006 at 21:24 UTC ( [id://585615]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      my $c = 0;
      for ($x = 0; $x <= 1; $x += 0.05){
    ...
        print "[$c] x= $x (".sprintf("%20.40f",$x).") \n";
    
        }
    
  2. or download this
    [1] x= 0 (0.0000000000000000000000000000000000000000)
    [2] x= 0.05 (0.0500000000000000027755575615628913510591)
    ...
    [18] x= 0.85 (0.8500000000000001998401444325281772762537)
    [19] x= 0.9 (0.9000000000000002442490654175344388931990)
    [20] x= 0.95 (0.9500000000000002886579864025407005101442)
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://585615]
Approved by Corion
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found