in reply to Why does this string comparison compares "numerically" and can I rely on this in general?
So, why does "eq" work like this
Because the internal representation of the two numbers is the same. Just because your code uses different formats to specify them does not affect how they are stored internally. Try this version of your code to see the values:
perl -we '$a = 1e-3; $b = 0.001; if ( $a eq $b ) { print "$a and $b ar +e equal.\n" }'
BTW, try to avoid $a and $b for arbitrary variables in real code because they have special meanings for sorting.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why does this string comparison compares "numerically" and can I rely on this in general?
by swl (Prior) on Apr 30, 2018 at 09:50 UTC |