Date: Mon, 14 Apr 2003 16:35:40 -0700
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject: Re: integer precision and mod function
Content-type: text/plain; charset=us-ascii
Bryan <bryan.munday@PAREXEL.COM> wrote:
> I'm trying to do some calculations with large integers (~10^23), and
> need accrate numbers. The problem is that I seem to be getting
> numerical inaccuracies with these numbers when compared to somethign
> as simple as Windows Calcualtor.
You're looking at round-off error. SAS is saving your numbers
as floating-point numbers, and losing precision off the back end
as your number of significant digits gets larger and larger.
If you want more than 16 significant digits, you'll be at risk of
round-off error, unless you do something drastic.
You *could* take the number apart and save a set number of digits in
a series of SAS variables, but then you'll have to write your own
math routines. If all you are doing is taking the modulus of integers,
this would be manageable.
Or you could do this in a package which would give you arbitrary
precision. Mathematica, for example, handles integers and rational
numbers exactly, while allowing you to psecify the precision on
irrational numbers. You could also use something like Perl, which
has several modules designed to deal with arbitrary-precision
numbers. I would suggest that you consider Perl with the Math::BigInt
module, which would solve the above problem.. even if it may not
handle problems which you neglected to post.
David Cassell, CSC
Senior computing specialist