Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: perl numeric expressions

by secret (Beadle)
on Nov 28, 2005 at 13:23 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2020-02-17 13:22 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (71 votes). Check out past polls.