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.

317 questions
0
votes
0 answers

Arbitrary.. imprecision arithmethics?

I'm currently implementing the game server for a little game idea I have in Java. The game will (eventually) deal with very large numbers, say 1e1000 or even bigger, so clearly all primitive datatypes are out since double is only around 1e320ish. So…
0
votes
1 answer

ApfloatMath.pow method returns almost the correct value

Here is a sample code: ApfloatMath.pow(new Apfloat(25, 5), new Apfloat(0.5, 5)); The above code performs the square root of 25. This returns 4.9999. I would've thought that this being arbitrary would return the correct value.
Dan Joe
  • 17
  • 1
  • 3
0
votes
2 answers

Bignum library, slow prime generator

I am developing a bignum library: http://pastebin.com/nFgF3zjW I implemented the Miller-Rabin algorithm (isprime()), but it is extremely slow, compared to for example OpenSSL's BN_is_prime_fasttest. I tried profiling and the functions that are…
Ledio Berdellima
  • 393
  • 1
  • 5
  • 10
0
votes
1 answer

Creating custom data type c++

I'm attempting to create a Number class that mimics an arbitrary precision data type. I want to be able to execute the following operations: Number a, b; cin >> a >> b; cout << "The sum of " << a << " and " << b << " is " << a+b << endl; Currently…
Brig
  • 123
  • 2
  • 3
  • 6
0
votes
1 answer

C++ How can I assign a datatype to a binary sequence?

I have a binary sequence. This sequence represents an arbitrary precision integer but as far as the computer is concerned, it's just a binary sequence. I'm working in C++, with the multiprecision library. I only know how to assign values to the…
Benn
  • 61
  • 1
  • 1
  • 3
0
votes
1 answer

Rounding at specific precision with ApFloat

ApFloat http://www.apfloat.org/ is a C/C++/Java math library that can calculate many trascendental operations such as square roots, exponentiations, logarithms, trigonometric/hyperbolic functions, numeric value of π, etc. with numbers of arbitrary…
0
votes
1 answer

Round arbitrary-length floats to n digits

I have already read most of the SO questions related to "rounding to n digits". I believe that this question is separate because it is more related to the rounding of arbitrary-length…
esote
  • 831
  • 12
  • 25
0
votes
1 answer

What is the difference between `Rational` and `BigNum` implementations

There are a lot of such types for many languages. As far as I know, here is how it works. Rational just stores two separate digits for numerator and denominator (like 3 and 10 for 0.3). BigNum stores each digit of the number in some kind of an…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
0
votes
1 answer

Arbitrary/Infinite precision variables - C#

Is there any type in C#that would allow me to store a fractional number with arbitrary or infinite precision? I don't want to use any external libraries--would I have to write a class myself? How would I do this? I need a variable to which I can…
vasilescur
  • 240
  • 2
  • 5
  • 16
0
votes
0 answers

Error returning value from overloaded function

I am working through a resource I found online for writing a library to handle arbitrary precision numbers. I have created the two files BigInt.h, containing the definitions of all the functions, and BigInt.cpp, containing all the implementations of…
Nick
  • 191
  • 1
  • 2
  • 9
0
votes
2 answers

Floating point decimals in python

I have a python script within which I define a variable called dt and initialize it as such: dt=0.30. For some specific reason, I have had to convert my python script into a C++ program, but the two programs are written to produce the exact same…
inquiries
  • 385
  • 2
  • 7
  • 20
0
votes
2 answers

Big integer division with operands aproximately of the same size

I'm trying to implement a function that computes the division between two numbers approximately of the same size. I use an array of unsigned int's to store the values of each number (see below the class structure). I want to implement an efficient…
fc67
  • 409
  • 5
  • 17
0
votes
1 answer

MPFR Program Crashes With High Precision

I recently wrote a program to calculate pi to a specified number of digits. The number of digits must be passed as the first command line argument. When run with a digit value under about 300 it works just fine. However, when run with a larger digit…
0
votes
3 answers

Is it possible to create an SVG that is precise to 1,000,000,000% zoom?

Split off from: https://stackoverflow.com/questions/31076846/is-it-possible-to-use-javascript-to-draw-an-svg-that-is-precise-to-1-000-000-000 The SVG spec states that SVGs use double-precision floats for all values. Through testing, it's easy to…
joshfindit
  • 611
  • 6
  • 27
0
votes
2 answers

How can Javascript be used to divide a circle equally so that it's correct to 1,000,000,000% zoom?

Split off from: https://stackoverflow.com/questions/31076846/is-it-possible-to-use-javascript-to-draw-an-svg-that-is-precise-to-1-000-000-000 Using floating point precision, there are rounding errors when calculating the position of points on a…
joshfindit
  • 611
  • 6
  • 27