in reply to problem with variables
It could be that they're not actually the same. Sure, they may look the same, but depending on what calculations were used to derive those numbers, their appearance may be deceiving to you; you could be getting bit by the floating point problems inherent in converting base two (binary) representations of numbers into base ten representations. This is discussed further in perlfaq4 under the heading, "Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?".
The short version of it is that it's problematic to perform equality comparisons on floating point numbers. This is not a Perl-specific issue; it exists for any language where numbers are represented internally in base-2 (binary).
Update: I just remembered an article that I found a year or so ago: What Every Computer Scientist Should Know About Foating-Point Arithmetic. It's an excellent article, and might qualify as "far more than you ever wanted to know", but definately will give you enough information to never fall for this type of bug again.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem with variables
by jeanluca (Deacon) on Oct 19, 2005 at 08:58 UTC |