PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l 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, easy-to-read 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:
   floating-point 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 single-precision 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

   Base-10 floating-point implementations don't have this anomaly.
   However, base-10 floating-point implementations are rare because
   base-2 (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 e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
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 e-mail transmission.  If 
verification is required please request a hard-copy 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.