LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2003, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 14 Apr 2003 16:35:40 -0700
Reply-To:     cassell.david@EPAMAIL.EPA.GOV
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.

HTH, David -- David Cassell, CSC Cassell.David@epa.gov Senior computing specialist mathematical statistician


Back to: Top of message | Previous page | Main SAS-L page