Date: Tue, 22 Dec 1998 10:35:41 -0500
Reply-To: Emil Hrivnak <eeh@VICON.NET>
Sender: "SPSSX(r) Discussion" <SPSSX-L@UGA.CC.UGA.EDU>
From: Emil Hrivnak <eeh@VICON.NET>
Subject: Re: greater than a negative number
In-Reply-To: <000301be2d47$d2865720$8a23400c@worldnet.worldnet.att.net>
Content-Type: text/plain; charset="us-ascii"
You can have one of two things going on here, or most likely, both.
First, since you're displaying the numbers to an F8.2 format, the number
stored internally in the computer isn't exactly what you are seeing when
it's displayed to 2 decimal places. You are rounding it to display it.
Internally the values are such that x is not exactly equal to 0.64 and y is
not exactly equal to -1.01. Try displaying the numbers with 16 or 17
decimal places showing. You should see the differences then. (Double
precision binary numbers have about 15, 16, 17 digits of decimal precision.
There are only enough bits in the internal representation to store the
number this accurately.)
The second item is that computers generally store numbers in binary. Unless
the decimal number you are using is exactly a combination of numbers that
can be represented as powers of 2, such as:
2 ^ 0 (2 to the zero power) = 1
2 ^ 1 = 2
2 ^ 2 = 4
2 ^ 3 = 8
2 ^ 4 = 16
. . .
2 ^ 10 = 1024 and so on
or numbers that are 1 over a power of 2, such as:
1 / (2 ^ 1) = 1/2
1 / (2 ^ 2) = 1/4
1 / (2 ^ 3) = 1/8
1 / (2 ^ 4) = 1/16
and so on, you cannot exactly represent the number in binary. 0.75 can
exactly be represented because it is a summation of 1/2 and 1/4. 0.33
cannot be exactly represented in the computer. Just ask yourself what is
1/3? Is it 0.3 or 0.33 or 0.3333 . . . 3333 with a thousand 3's. That's
still not the exact value. Computations done with real numbers that are not
summations of 2 to a power and 1 over 2 to a power will not be exact.
They'll be correctly rounded to 15 or 16 decimal digits of precision, but
not exact.
You have to work around it by deciding how many digits of precision you
want, multiply the number by a power of ten, truncated it, and then compare
those results.
By the way, if you try some of these on a calculator, or a Lotus or Excel
spreadsheet, you'll see different answers. Calculators and those
spreadsheets generally do their internal calculations in decimal, rather
than binary. It's slower and more wasteful, but the general population and
accountants don't like roundoff when working with decimal numbers. We don't
either. But for speed, computers generally work in binary.
E Hrivnak
eeh@vicon.net
At 03:09 PM 12/21/98 -1000, you wrote:
>Aloha everybody:
>
>Looking for an explanation for the following:
>
>I have two numeric variables (F8.2), say x=.64; y=1.65.
>
>I have the following syntax:
>
> If ((x-y) > -1.01) z=1.
>
>When I execute this command, I get z=1. Why ?
>
>Mark Scott Verschell
>1427 A Dominis Street
>Honolulu, Hawaii 96822
>mverschell@worldnet.att.net
>
>