Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: perl numeric expressions

by secret (Beadle)
on Nov 28, 2005 at 13:23 UTC ( [id://512164]=note: print w/replies, xml ) Need Help??


in reply to perl numeric expressions

If you use eq instead of == it yields the correct result :

#!/usr/bin/perl use strict; use warnings; my $x1 = 44.7; my $x2 = 44.9-0.2; print "numbers $x1 $x2 - "; if ($x1 eq $x2) { print "SAME\n"; } else { print "NOT SAME\n"; }

.. but I'm not sure as why it is so !?

Replies are listed 'Best First'.
Re^2: perl numeric expressions
by tphyahoo (Vicar) on Nov 28, 2005 at 13:35 UTC
    it's because "eq" compares strings, not numbers.

      So it means that internally doing eq on a "number" is like doing the appropriate sprintf and == and that's how "extrapolation" of a number into a string works ?

        not really sure of the gory details. But I think the term you want if you're going to be googling around for more info could be "stringification". The opposite would be "nummification."

        UPDATE: But you better double check that. These may be perl 6 only terms. (And it was just a guess.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found