Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: 0.99999998 (was: Unknown SQL)

Re: 0.99999998 (was: Unknown SQL)

From: Sam Staton <sam.staton_at_bigfoot.com>
Date: Sat, 21 Jul 2001 23:29:29 GMT
Message-ID: <792lht8oad2s0qntl9b74claoavps3kmea@4ax.com>

>>Let x := -0. Let y := +0. Assume IEEE arithmetic. The following are
>>true.

 ...
>>c) If you test 1/x == 1/y, you get false.
>
>Actually, you should get a divide by zero error. Both sides of the
>comparison are undefined.

Actually, you get false. I choose Java, since it is recent enough to guarantee full IEEE support. Try it yourself, or check the IEEE standard. In IEEE arithmetic, you only get 'errors' if you explicitly install trap handlers or inspect status flags. This is partly because in many cases, the value 'Infinity' is not an 'error'. Also, in true IEEE arithmetic 1/0 is treated differently from an overflow.

double x;
double y;
x = -0.0;
y =  0.0;
System.out.println(x);            // prints '-0.0'
System.out.println(y);            // prints '0.0'
System.out.println(1/x);          // prints 'Infinity' 
System.out.println(1/y);          // prints '-Infinity'
System.out.println(1/x == 1/y); // prints 'false'

Read David Goldberg: 'What Every Computer Scientist should know about Floating-Point Arithmetic', ACM Computing Surveys, Vol 23, No 1, March 1991.

If you have further comments, can we discuss in comp.theory, where those who know more about these things hang out?

Cheers

Sam Received on Sat Jul 21 2001 - 18:29:29 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US