Date: Wed, 27 Sep 2006 05:02:11 -0400
Reply-To: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject: Re: Precision of Scientific Calculation
default precision? Not easy to say. The numbers in SAS are binary, not
binary coded (BCD). Unfortunately you have there a problem because the
numbers are transformed from decimal to binary. The precision (the number of
significant decimals) is limited by the used memory. The same for BCD
arithmetic, but the precision is more predictable, but needs more memory.
Short: in BCD arithmetic you use a half-byte for 10 decimals (1 position,
0-9), in binary you use all what's there.
In SAS the default and max-length for numerics is 8 byte long. 8 byte are 64
bits of 0 or 1. The number, you can store in there is not big enough, so a
"trick" is used. The number is split in a exponent and a mantissa. 1 byte is
for the exponent, 7 for the mantissa. The mantissa is the part which is
responsable for the precision. So you have 7 bytes free for that. 7 bytes
are 7*8 bits = 56 bits. 1 you need for the sign, so 55 are left. 55 binary
places is the number you can use. Theoretical the max number in decimal is
2**55 = 36,028,797,018,963,968
Thats a bit theoretical, because you have several problems to solve with
arithmetics. One of them is the "overflow" problem. Imagine a short mantissa
with 4 bits, one of them (the most left-one) for the sign. Start with 0000
and define the addition. 0000+1 = 0001 (1 in dec). 0001+1=0010 (=2 in dec)
... 0111 (7 in dec). Adding 1 returns 1000. that should be 8 in decimal? No!
The leftmost bit is the sign, so it is -7 (the binary complement). Such
things you must take care of by implementing a arithmetic and many more!
It's not easy to implement that, including the decimal representation.
Nobody would be satisfied with binaries in his report, so it has to be
transformed to be represented in the machine and the results have to be
retransformed to be shown outside. Both is not easy. So there might be a
problem with that. The problem is the same with 1 and 0.00000001! That's no
difference. Both are split in mantissa and exponent, so the only difference
is in the exponent. So it does not matter. The problem is in calculations,
which might result in things like 1.00000000000000001 or 0.99999999999999
instead. Thats nearly equal, but not really. Also with more memory, you
simply get longer chains of 9's but no exact result. With BCD that would be
possible, because each of the single decimal places are represented exactly
and the arithmetics are implemented totally different. Unfortunately not in
SAS and you must be careful there. Rounding sometimes might be a good idea
to make 1.000000 and 0.999999 equal if that fits to your needs.
Regards,
Gerhard
On Wed, 27 Sep 2006 00:34:00 -0700, RolandRB <rolandberry@HOTMAIL.COM> wrote:
>Li Zhang wrote:
>> I am doing some scientific calculation which involve
>> manipulating numbers as small as 0.000001. But I get
>> some weird results. I suspect it is due to the
>> rounding error. What is the default precision of
>> SAS(9.0), how can I increase it?
>>
>> Thank you
>>
>> Li
>
>Show us what you are typically trying to calculate and how.
|