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

Re^2: Why is this comparison failing?

by johnrcomeau (Novice)
on Oct 08, 2015 at 22:21 UTC ( [id://1144243]=note: print w/replies, xml ) Need Help??


in reply to Re: Why is this comparison failing?
in thread Why is this comparison failing?

Dave- Thanks. I should have known better. But I was misled by what I assumed was Perl's rules for how variables were used to build double-quoted strings. I would have thought that floating point numbers that are not integers would show enough decimal places to indicate such. That's how I was misled into thinking that these cases were identical. I realize that I actually don't know how numbers are evaluated for double-quoted strings. Do you have a good reference? Regards, John

Replies are listed 'Best First'.
Re^3: Why is this comparison failing?
by mr_ron (Chaplain) on Oct 09, 2015 at 01:18 UTC
    It's not really about string representation or integers. It may be more about the limits of Perl 5 and most programming languages in dealing with fractions and floating point. For example:
    perl -Mstrict -w -e 'if (0.3 == 0.1 * 3) { print "equals\n" } else { p +rint "* difference * ", abs(0.3 - 0.1 * 3), "\n" }' * difference * 5.55111512312578e-17
    Ron
Re^3: Why is this comparison failing?
by dave_the_m (Monsignor) on Oct 09, 2015 at 08:45 UTC
    I'm not sure it's documented anywhere. The number of significant digits it uses varies by platform, but typically it stringifies a float to 15 significant digits, with trailing 0's excised.

    Dave.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-24 22:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found