Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Fun with floating points

by kikuchiyo (Monk)
on Nov 06, 2009 at 15:04 UTC ( #805500=note: print w/ replies, xml ) Need Help??


in reply to Re: Fun with floating points
in thread Fun with floating points

I had a reason to post it as I did.

In the actual application where I had this issue, the workflow was something like this: data was read off from data files and stored in a Storable file. Later, these Storable files were retrieved, and the data in them was further processed. And finally I used a numerical comparison to get the result (is the number dug up from the Storable archives bigger than a pre-specified limit). However, Storable stores floating point numbers as text, at least it did in my application.

So the real issue here is that it is awesomely convenient to have scalars-that-are-both-numbers-and-strings in Perl, but one has to be careful and know that it may lead to strange results sometimes.


Comment on Re^2: Fun with floating points
Re^3: Fun with floating points
by chomzee (Beadle) on Nov 08, 2009 at 10:41 UTC
    String/float conversion is not the only problem while dealing with floats. Consider following example:
    perl -e '$x=1/3; $x-=1/2; $x+=1/3; $x-=1/2; $x+=1/3; print $x,"\n"'
    $x should be equal to zero but it isn't.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-07-25 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (170 votes), past polls