Date: Tue, 20 Dec 2005 08:37:21 -0800
Reply-To: "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Subject: Re: Numeric Precision Problem
Content-Type: text/plain; charset="us-ascii"
Thanks Ed for elaborating! :o)
Appreciate you taking the time.
From: Ed Heaton [mailto:EdHeaton@westat.com]
Sent: Tuesday, December 20, 2005 8:31 AM
To: Terjeson, Mark (IM&R); SAS-L@LISTSERV.UGA.EDU
Subject: RE: Re: Numeric Precision Problem
Consider the following code.
Data _null_ ;
Do i=0 by 0.01 until ( i eq 0.1 ) ;
Put i= binary64. ;
This would loop only 11 times if SAS could accurately store 0.01 and
0.1. However, SAS can't.
Let's look at the was SAS stores 0.1 ...
1 Data _null_ ;
2 x = 0.1 ;
3 Put x= binary64. ;
4 Run ;
Now, the first byte is the sign (0 means positive), the next 11 bits
represent the exponent and the remainder of the bits represent the
decimal part of the mantissa. The integer part of the mantissa is
always 1 and is not stored.
Look at the mantissa. It is a repeating pattern of 1001. In fact, if
you were to store 0.1 accurately in this binary format, the repeating
pattern of 1001 would never end. That is much the same as 1/3 expressed
in decimal creates a repeating pattern that never ends.
So, SAS can't store 0.1 accurately.
Edward Heaton, SAS Senior Systems Analyst,
Westat (An Employee-Owned Research Corporation),
1600 Research Boulevard, RW-4541, Rockville, MD 20850-3195
Voice: (301) 610-4818 Fax: (301) 294-3879