Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Is this odd behavior a floating point problem?

by roboticus (Chancellor)
on Mar 23, 2012 at 17:25 UTC ( #961269=note: print w/ replies, xml ) Need Help??


in reply to Is this odd behavior a floating point problem?

wickedjester:

You don't show your code, but I'm pretty sure you're not doing what you think you're doing. Specifically, I believe you're adding 41 copies of 0.001, as that's the only way I can reproduce your results:

$ cat t.pl #!/usr/bin/perl my @a = (0.001) x 41; my $sum=0; $sum += $_ for @a; print "Avg: ", $sum/40, "\n"; $ perl t.pl Avg: 0.001025

...roboticus

When your only tool is a hammer, all problems look like your thumb.


Comment on Re: Is this odd behavior a floating point problem?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2015-07-28 09:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls