
sybperll Archive
Up Prev Next
From: Steve Baumgarten <sbb at panix dot com>
Subject: Re: DBD::Sybase 1.07 install on Solaris 8  failing t/exec.t test
#11
Date: Nov 2 2005 9:42PM
Greg Earle wrote:
>> Floats tend to do this from time to time.
>> Reason I tend use decimal instead.
>
> So, what's the consensus  do I just change the test in exec.t
> to match my returned mutant results? :) And do a "make test"
> and "make install" manually, ignoring the mismatched results?
Mix floats and the == operator and you're bound to be surprised sooner
or later. One must compare to a certain desired precision. You want
something like:
my $epsilon = 0.001;
if( abs( $a  $b ) > $epsilon ) {
# numbers are different
} else {
# numbers are the same
}
Here's an excellent, easytoread discussion, "The Perils of Floating
Point":
http://www.lahey.com/float.htm
Examples are given in Fortran, but even those not familiar with it can
make sense of what the code is doing.
An excerpt from the article:
At the heart of many strange results is one fundamental:
floatingpoint on computers is usually base 2, whereas the external
representation is base 10. We expect that 1/3 will not be exactly
representable, but it seems intuitive that .01 would be. Not so! .01
in IEEE singleprecision format is exactly 10737418/1073741824 or
approximately 0.009999999776482582. You might not even notice this
difference until you see a bit of code like the following:
REAL X
DATA X /.01/
IF ( X * 100.d0 .NE. 1.0 ) THEN
PRINT *, 'Many systems print this surprising result. '
ELSE
PRINT *, 'And some may print this.'
ENDIF
Base10 floatingpoint implementations don't have this anomaly.
However, base10 floatingpoint implementations are rare because
base2 (binary) arithmetic is so much faster on digital computers.
Feel free to blame base 2 floating point arithmetic. It's fast, it's a
standard (IEEE 754), but it causes no end of grief when people attempt
to use the == operator to determine whether two floating point numbers
are equal.
SBB
Visit our website at http://www.ubs.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this email. Please
notify the sender immediately by email if you have received this
email by mistake and delete this email from your system.
Email transmission cannot be guaranteed to be secure or errorfree
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of email transmission. If
verification is required please request a hardcopy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.
