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
4
votes
3 answers

Long Multiply C

I'm trying to implement the long multiply method (grade school method) in C. I need to write my program in base 2^32. I'm not sure how to even start. I have the algorithm that I want to use here: for (i = 0; i < n; i++) { carry = 0; for (j =…
Chaz
  • 63
  • 7
4
votes
1 answer

Unexpected error in Julia set rendering

I am playing with Mandelbrot and Julia sets and I encountered interesting problem. The Mandelbrot set can be rendered in double precision until zooms of around 2^56 at any place. However, the Julia set sometimes produces artifacts much sooner like…
NightElfik
  • 3,834
  • 4
  • 22
  • 34
4
votes
1 answer

BigDecimal.divide() yields extra digit of precision when called with a MathContext

Given the simple program import java.math.*; import static java.math.BigDecimal.ONE; import static java.lang.System.out; public static void main(String[] args) { StringBuffer ruler = new StringBuffer(" "); for (int i = 0; i < 5; i++) { …
200_success
  • 6,669
  • 1
  • 36
  • 68
4
votes
2 answers

I need to calculate Stirling's approximation very fast

I'm writing a small library for statistical sampling which needs to run as fast as possible. In profiling I discovered that around 40% of the time taken in the function is spent computing Stirling's approximation for the logarithm of the factorial.…
pg1989
  • 980
  • 5
  • 12
4
votes
3 answers

arbitrary precision linear algebra c/c++ library with complex numbers

I'm doing a research involving linear differential equations with complex coefficients in 4-dimensional phase space. To be able to check some hypothesis about the root of the solutions, I need to be able to solve these equations numerically with…
Ilya V. Schurov
  • 6,560
  • 2
  • 30
  • 71
4
votes
1 answer

Calculating the digits of pi

I've used the GMP library and C++ to code an implementation of the Gauss-Legendre algorithm to calculate the digits of pi. It has correct output, but the problem is I don't know at which point the output "turns bad", since I have to specify the…
4
votes
1 answer

No solution in CPLEX with very small change in inputs

I'm using CPLEX in C++ to solve a hub location problem, a MIP, and I've recently found a very precise set of inputs that CPLEX thinks is infeasible (i.e. CPXMIP_INFEASIBLE) even though the problem is certainly feasible. The problem appears to…
3
votes
2 answers

How do pocket calculators simplify fractions and keep imprecise numbers as fractions?

Could someone explain how calculators (such as casio pocket ones) manage equations such as '500/12' and are able to return '125/3' as the result, alternately can someone name some algorithms which do this? By imprecise numbers I mean numbers which…
3
votes
3 answers

what options are there for representing numbers with more than 2^81 digits?

I came across an interesting math problem that would require me to do some artithmetic with numbers that have more than 281 digits. I know that its impossible to represent a number this large with a system where there is one memory unit for each…
Letseatlunch
  • 2,221
  • 4
  • 26
  • 32
3
votes
2 answers

Logarithm of the very-very large number

I have to find log of very large number. I do this in C++ I have already made a function of multiplication, addition, subtraction, division, but there were problems with the logarithm. I do not need code, I need a simple idea how to do it using…
Kamil Hismatullin
  • 257
  • 2
  • 5
  • 15
3
votes
1 answer

Python Native Arbitrary Precision

Is there any way of compiling Python's interpretter in such a way that it could use a native (c) arbitrary precision library so that Python could use arbitrary precision as if it was a normal number instead of having to use the decimal…
Jim Jeffries
  • 9,051
  • 13
  • 57
  • 99
3
votes
1 answer

How to get higher precision for sine using the Arb library?

I found the Arb library, which should be able to compute very high precision values of sine, given enough time. However, I am unable to. Trying the sine example, I could get the predicted output. However, when I tried to increase the precision by…
Ritesh Singh
  • 245
  • 1
  • 4
  • 17
3
votes
1 answer

Using multiple precision in bare-metal c

So I have a raspberry pi zero and I followed along this really cool tutorial to have a starting point at programming it in bare metal c. Everything's been working good. Now for what I want to do I need (unsigned) integers with a size of 256 or 512…
Rubydragon
  • 31
  • 1
  • 2
3
votes
2 answers

Different results for the same problem solution in node.js and python

I solved the following leetCode problem with some code : You have d dice, and each die has f faces numbered 1, 2, ..., f. Return the number of possible ways modulo 10^9 + 7 to roll the dice so the sum of the face up numbers equals t. I made two…
3
votes
3 answers

Subtracting signed binary numbers without two's complement

So I'm trying to write code to subtract two binary numbers but I'm not sure how to tackle this problem elegantly. The structures that hold the binary numbers are as follows. typedef struct _bitb { short bit; struct _bitb *nbit; }…
chilliefiber
  • 461
  • 2
  • 5
  • 15