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
7
votes
2 answers

How can I use arbitrary length integers in Perl?

Is there any standard way to use integers of arbitrary length in Perl? I am working on code that generates x64 assembly for tests, and I'm tired of manipulating 32 bits at a time. I'm using Perl 5.10.0, for what it's worth.
Nathan Fellman
  • 108,984
  • 95
  • 246
  • 308
7
votes
2 answers

Fractions with decimal precision

Is there a pure python implementation of fractions.Fraction that supports longs as numerator and denominator? Unfortunately, exponentiation appears to be coded in to return a float (ack!!!), which should at least support using decimal.Decimal. If…
Noah
  • 17,200
  • 7
  • 59
  • 68
7
votes
2 answers

What is the precise meaning of arbitrary precision?

This might be a very simple question for some but I would like to know the meaning of arbitrary precision which appears in the first line in JavaDoc of BigInteger : Immutable arbitrary-precision integers .
Geek
  • 23,609
  • 39
  • 133
  • 212
6
votes
3 answers

How to determine before hand if an unsigned calculation may possibly overflow?

As a personal project I am working on implementing an Arbitrary Precision number type for a pet project of mine. I already know about all the popular, tested and robust libraries out there that do this. I want to work on a solution as a self…
user177800
6
votes
0 answers

Go Protobuf Precision Decimals

What is the correct scalar type to use in my protobuf definition file, if I want to transmit an arbitrary-precision decimal value? I am using shopspring/decimal instead of a float64 in my Go code to prevent math errors. When writing my protobuf…
Matt Mc
  • 7,604
  • 5
  • 47
  • 82
6
votes
1 answer

Can I use a `mpfr_t` as both input and output argument?

The question is very simple and direct, but I could not find an answer on the documentation. If I have mpfr_t a, b; Can I do something like mpfr_add(a, a, b, rnd); This would compute the sum of a and b and store the result on a. I don't know if…
Spiros
  • 1,853
  • 2
  • 17
  • 38
6
votes
3 answers

Number type boundaries in Common LISP and Stack flowing over in GHCI

First question ever here, and newbie in both Common LISP and Haskell, please be kind. I have a function in Common LISP - code below - which is intended to tell whether the area of a triangle is an integral number (integer?). (defun area-int-p (a b…
zweiblumen
  • 91
  • 2
  • 7
6
votes
1 answer

SIMD versions of SHLD/SHRD instructions

SHLD/SHRD instructions are assembly instructions to implement multiprecisions shifts. Consider the following problem: uint64_t array[4] = {/*something*/}; left_shift(array, 172); right_shift(array, 172); What is the most efficient way to implement…
Vincent
  • 50,257
  • 51
  • 171
  • 339
6
votes
2 answers

Hash an arbitrary precision value (boost::multiprecision::cpp_int)

I need to get the hash of a value with arbitrary precision (from Boost.Multiprecision); I use the cpp_int backend. I came up with the following code: boost::multiprecision::cpp_int x0 = 1; const auto seed = std::hash{}(x0.str()); I…
Alexandre Hamez
  • 6,713
  • 2
  • 26
  • 36
6
votes
8 answers

Has arbitrary-precision arithmetic affected numerical analysis software?

Has arbitrary-precision arithmetic affected numerical analysis software? I feel that most numerical analysis software keeps on using the same floats and doubles. If I'm right, I'd love to know the reason, as in my opinion there are some calculations…
Liran Orevi
  • 4,507
  • 7
  • 44
  • 63
5
votes
3 answers

Is there support for arbitrary precision arithmetic in C#?

Does C# support arbitrary precision arithmetic (I think this is also called bignums)? If it doesn't, which libraries do support it?
5
votes
1 answer

Arbitrary Precision Arithmetic (Bignum) for 16-bit processor

I'm developing an application for a 16-bit embedded device (80251 microcontroller), and I need arbitrary precision arithmetic. Does anyone know of a library that works for the 8051 or 80251? GMP doesn't explicitly support the 8051, and I'm wary of…
Eric
  • 51
  • 1
5
votes
2 answers

Redis support arbitrary precision in LUA Scripts

I need to be able to make a transaction in redis that does the following: decrement n value if and only if the result is > 0 otherwise, do nothing deal with arbitrary precision decimal numbers (I need them in a float format) be accessible to other…
Quadear
  • 257
  • 1
  • 8
5
votes
3 answers

Restore a number from several its remainders (chinese remainder theorem)

I have a long integer number, but it is stored not in decimal form, but as set of remainders. So, I have not the N number, but set of such remainders: r_1 = N % 2147483743 r_2 = N % 2147483713 r_3 = N % 2147483693 r_4 = N % 2147483659 r_5 = N %…
osgx
  • 80,853
  • 42
  • 303
  • 470
5
votes
2 answers

Obtain first significant digits of a number using variable-precision arithmetic

Assume you want to know the first W significant digits of a number, say pi, using vpa. Simply calling vpa with that many digits does not work. Consider the following example with W = 35: >> disp(vpa(sym('pi'),…
Luis Mendo
  • 106,541
  • 12
  • 66
  • 138
1 2
3
19 20