multi precision arithmetic

Kent Boortz kent@REDACTED
Tue Apr 15 15:42:59 CEST 2003


Marc Ernst Eddy van Woerkom <Marc.Vanwoerkom@REDACTED> writes:
> I have a task which involves writing a small arithmetics lib
> (+ - * / < = >) that should be able to calculate exact results
> for a given number of digits behind the radix point and is
> able to handle digits from different (integer) bases.
> 
> Correctness is more important than speed or efficient memory
> usage.

I'm I correct that you want to calculate things like

   0x34FA.FF21 * 100.566

? And that you can use any programming language? You can probably use
the rational numbers in the GMP C library, i.e. first convert your
numbers to rational numbers, perform the calculations and convert it
back to your format. See

  http://www.swox.com/gmp/manual/Rational-Number-Functions.html

Writing a small package in Erlang to do rational number arithmetics
without any demands on speed is probably a fun exercise but I think
some operations like '<' and '=' on rational numbers are not as
trivial as they may seem as first. The operands need to be
canonicalized,

kent


  0x34FA.FF21 * 100.566 =>
  (0x34FAFF21 / 16**4) * (100566 / 10**3) =>
  (888864545 /  16**4) * (100566 / 10**3) =>
  (888864545 * 100566) / (16**4 * 10**3)
  .
  .



More information about the erlang-questions mailing list