Questions tagged [arbitrary-precision]

All questions concerning numbers which support extremely high precision: Libraries in programming languages (GMP, MPFR), support of arbitrary precision in computer algebra systems (CAS, Mathematica, Maple, Mathlab) and how to correctly use and calculate numbers with very high precision and accuracy.

Sometimes the available precision of hardware-supported datatypes (most likely single precision (=32bit), double precision (=64bit), extended precision (=80bit)) is not enough to tackle some problems:

  • Problems given in natural sciences and applied and theoretical mathematics which needs utmost precision. These are mostly tackled by computer algebra systems like Mathematica and Maple.
  • Financial applications which must confirm to the exact rounding procedures given by law. They also should guarantee that the available range of numbers is big enough so that nonsensical results by leaving the supported range (overflow) will not occur.
  • Cryptological applications which need to handle very large integers because many algorithms (integer factorization, Diffie-Hellman key exchange) are based on them.

In this case speed and portability is sacrificed to support numbers with a much higher precision available than hardware-supported datatypes. They are called arbitrary-precision numbers.

As the handling of arbitrary-precision numbers and arithmetic is not standardized yet, there may be big differences between implementations. There are different packages supporting one or more arbitrary-precision datatypes: integer, binary and decimal float or rational.

The tag should be applied to all questions which need to use arbitrary-precision numbers: Problems which need high precision, the implementation of arbitrary-precision numbers, the programming of basic operations, known caveats of specific packages etc. Some programming languages have built-in capabilities to handle arbitrary-precision (BigDecimal in Java, Bignum in Ruby).

Free software:

Axiom: Free computer algebra system with arbitrary-precision capabilities.

GMP: GNU Multiple Precision Arithmetic Library

Important books:

Knuth, D. E. The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 3rd ed. Reading, MA: Addison-Wesley, 1998.

Muller, Jean-Michel et al. Handbook of Floating-Point Arithmetic, Chapter 14, Birkhäuser Boston, 2009.

296 questions
33
votes
6 answers

What class to use for money representation?

What class should I use for representation of money to avoid most rounding errors? Should I use Decimal, or a simple built-in number? Is there any existing Money class with support for currency conversion that I could use? Any pitfalls that I should…
Esteban Küber
  • 33,970
  • 13
  • 78
  • 96
30
votes
2 answers

What is the fastest way to calculate e to 2 trillion digits?

I want to calculate e to 2 trillion (2,000,000,000,000) digits. This is about 1,8 TiB of pure e. I just implemented a taylor series expansion algorithm using GMP (code can be found here). Unfortuanetly it crashes when summing more than 4000 terms on…
iblue
  • 26,668
  • 17
  • 81
  • 125
23
votes
1 answer

Can long integer routines benefit from SSE?

I'm still working on routines for arbitrary long integers in C++. So far, I have implemented addition/subtraction and multiplication for 64-bit Intel CPUs. Everything works fine, but I wondered if I can speed it a bit by using SSE. I browsed through…
cxxl
  • 4,014
  • 3
  • 25
  • 46
21
votes
18 answers

What programming languages support arbitrary precision arithmetic?

What programming languages support arbitrary precision arithmetic and could you give a short example of how to print an arbitrary number of digits?
Matt Gregory
  • 6,184
  • 5
  • 29
  • 36
19
votes
1 answer

How to multiply terabyte-sized numbers?

When multiplying very large numbers, you use FFT based multiplication (see Schönhage–Strassen algorithm). For performance reason I'm caching the twiddle factors. The problem is for huge numbers (Gigabyte-sized) I need FFT tables of size 2^30 and…
iblue
  • 26,668
  • 17
  • 81
  • 125
18
votes
5 answers

numpy arbitrary precision linear algebra

I have a numpy 2d array [medium/large sized - say 500x500]. I want to find the eigenvalues of the element-wise exponent of it. The problem is that some of the values are quite negative (-800,-1000, etc), and their exponents underflow (meaning they…
jarondl
  • 1,373
  • 4
  • 17
  • 26
17
votes
1 answer

Is Python incorrectly handling this "arbitrary precision integer"?

Python is supposed to have "arbitrary precision integers," according to the answer in Python integer ranges. But this result is plainly not arbitrary precision: $ python -c 'print("%d" %…
Jeff Snider
  • 740
  • 1
  • 6
  • 20
17
votes
1 answer

AVX VMOVDQA slower than two SSE MOVDQA?

While I was working on my fast ADD loop (Speed up x64 assembler ADD loop), I was testing memory access with SSE and AVX instructions. To add I have to read two inputs and produce one output. So I wrote a dummy routine that reads two x64 values…
cxxl
  • 4,014
  • 3
  • 25
  • 46
16
votes
2 answers

Arbitrary-Precision Math in PHP

I'm currently trying to figure out how to work with arbitrary-precision numbers in PHP. So I guess my first question would be what exactly is arbitrary-precision math. I tried Googling for a good definition but for some reason nobody can put it in…
parent5446
  • 868
  • 7
  • 17
14
votes
7 answers

How to work on big integers that don't fit into any of language's data structures

I'm trying to solve a programming contest's preliminary problems and for 2 of the problems I have to calculate and print some very big integers(like 100!, 2^100). I also need a fast way to calculate powers of this big integers. Can you advice me…
sinan
  • 6,302
  • 5
  • 31
  • 62
14
votes
3 answers

Large numbers in Pascal (Delphi)

Can I work with large numbers (more than 10^400) with built-in method in Delphi?
regexp
  • 263
  • 2
  • 7
13
votes
3 answers

Handle arbitrary length integers in C++

Can someone tell me of a good C++ library for handling (doing operations etc...) with arbitrarily large numbers (it can be a library that handles arbitrary precision floats too, but handling integers is more important)? Please only refer to…
wxiiir
  • 318
  • 3
  • 15
13
votes
2 answers

Exact real arithmetic and lazy list performance in C++/Haskell

I recently came across the subject of exact real arithmetic after reading this paper and this paper. I have found a number of papers that discuss realizations of exact arithmetic using signed digit streams. The use of infinite streams for arbitrary…
13
votes
5 answers

PHP gives incorrect results when formatting long numbers

I am working with huge numbers for website purposes and I need long calculation. When I echo a long number I don't get the correct output. Example // A random number $x = 100000000000000000000000000; $x = number_format($x); echo "The number is: $x…
deerox
  • 967
  • 3
  • 10
  • 26
13
votes
2 answers

Compute the product a * b² * c³ ... efficiently

What is the most efficient way to compute the product a1 b2 c3 d4 e5 ... assuming that squaring costs about half as much as multiplication? The number of operands is less than 100. Is there a simple algorithm also for the case that the…
maaartinus
  • 40,991
  • 25
  • 130
  • 292
1
2 3
19 20