multi precision arithmetic

Marc Ernst Eddy van Woerkom Marc.Vanwoerkom@REDACTED
Tue Apr 15 16:57:02 CEST 2003

>      0x34FA.FF21 * 100.566


> ? And that you can use any programming language? 

Of course. The final implementation is in a language so outdated I
don't dare to mention it here. :)

> You can probably use the rational numbers in the GMP C library

I would rather go for their integers which are some

  [sign, a_n, .. , a_0, a_-1, .., a_-k]

representation. a_i is the coefficient/digit to b^i.
k ist the number of guaranteed digits behind the radix point,
in case of non terminating divisions like 1/3. 

But GNU bc and also GMP (if I am not wrong) seem to do the calculation 
in decimal base and do base conversions before and after.
The problem is precision (k or scale) one tells that software to guarantee 
is given for decimal rounding:

  obase=10 # note this means hex 10 = dec 16!
  AF.F0000000 # 10 digits dec seen to be about 8 digits hex
  AF.F      # my input
  AF.E      # output 175.9 because this is 1 digit *decimal* rounding!

A workaround is a formula that tells you how many digits precision
in the intended base are equivalent to p digits in decimal representation:

  t = CEIL((p * log(10) / log(base))) + 3

Funny is that I found nothing that does the maths directly in base 29
for example.

> Writing a small package in Erlang to do rational number arithmetics
> without any demands on speed is probably a fun exercise

I just want an independend implementation for testing purposes.

But what is curious with Erlang is that it has already
some rudimenatary aribitrary precision maths built in.
I just don't find the docs and I don't know why it
was put in the first place because it seems to feature
just a little bit of the usual maths of that kind.


More information about the erlang-questions mailing list