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.)