## integer precision and mod function

### integer precision and mod function

Hi,

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.  I wasn't sure which was the correct
number so started doingsome mod calculations as well and when compared
to another system SAS seems to give up eg

mod(129**11,49) = 0
mod(128**11,49) = 0
(I've repreogrammed this without the mod function and get the same
values)
Both accorging to SAS, PL/SQL gives more believeable results of 19 and
18 respectively.

If anyone could tell what level of accuracy and precission I can
expect from SAS (v8 windows and VMS), and if the mod function works at
with these large numbers.

TIA

Bryan

### integer precision and mod function

Bryan,

This may be of some help to you -

TIP00330 - Significant Digits, Numeric 101 by SAS Institute

http://www.sconsig.com/sastips/tip00330.pdf

HTH,
Charles Patridge

### integer precision and mod function

> 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

Senior computing specialist
mathematical statistician

I am interested in experimenting on the CM5 with multi-precision
integer routines for number theory applications (in particular
factorization).  Any source code (CM Fortran of C*) would be most
welcome.  Are there any ftp sites for such code?