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

Arbitrary precision unsigned integer supporting just post increment operator

I am looking for a very simple C++ class implementing an unsigned integer with arbitrary precision and just the post increment operator. I know there are library for arbitrary precision integer arithmetic but my needs are quite simple and I prefer…
Alessandro Jacopson
  • 16,221
  • 13
  • 91
  • 139
0
votes
2 answers

C++: Boost cpp_dec_float Independent?

I just downloaded Boost because I need the precise floating-point arithmetic found in cpp_dec_float.hpp; I looked around a lot for other options, and couldn't find a good alternative. I spent a while figuring out how to install bcp, and now I've…
Caleb P
  • 301
  • 1
  • 2
  • 14
0
votes
2 answers

"Multiplication of Arbitrary Precision Numbers" in Scheme

The following is code to a problem that I have been working on for a few days. The problem I encountered is that for some reason when I call: (apa-multi '(7 3 1 2) '(6 1 4)) the return is: '(4 8 9 5 6 8) The answer that it should output is '(4 4…
0
votes
1 answer

arbitrary precision addition using lists of digits

What I'm trying to do is take two lists and add them together like each list is a whole number. (define (reverse lst) (if (null? lst) '() (append (reverse (cdr lst)) (list (car lst))))) (define (apa-add l1 l2) (define (apa-add-help…
0
votes
2 answers

Storing arbitrary precision integers

I am writing a little arbitrary precision in c(I know such libraries exist, such as gmp, nut I find it more fun to write it, just to exercise myself), and I would like to know if arrays are the best way to represent very long integers, or if there…
user2546845
0
votes
1 answer

Looking for Ansi C89 arbitrary precision math library

I wrote an Ansi C compiler for a friend's custom 16-bit stack-based CPU several years ago but I never got around to implementing all the data types. Now I would like to finish the job so I'm wondering if there are any math libraries out there that I…
Anthony
  • 584
  • 3
  • 18
0
votes
3 answers

Find Pi to the Nth Digit

I'm beginning to teach myself C++ until my class starts in the fall. I was wondering if you might be able to help me come up with a better way to ask the user for the number of digits they want for the number pi, and then display it. My problem is…
Binka
  • 111
  • 3
  • 10
0
votes
4 answers

Java: Display float with precision of 30

I'm trying to calculate PI with some algorithms, but the main thing is to display it with precision of 30. I tried to output a string with format etc. But it seems that maximum precision of double is 15. Is there any class or some method to help me…
ashur
  • 3,661
  • 12
  • 46
  • 76
0
votes
1 answer

Arbitrary precision package

I'm having trouble with this arbitrary precision package. I included "precisioncore.cpp", declared an int_precision, tried to compile and it told me that stdafx.h was missing. I already read that I can simply omit this include in precisioncore.cpp,…
alexander remus
  • 379
  • 1
  • 3
  • 10
0
votes
1 answer

Matlab: Loss of precision in calculations. Scaling of variables possible?

Today I ran into a problem with precision in Matlab: Tp = a./(3600*sqrt(g)*sqrt(K).*u.*Sd*sqrt(bB)) where a = 346751.503002533 g = 9.81 bB = 2000 Sd = 749.158805838953 …
0
votes
1 answer

Keeping accuracy when taking decimal to power of integer

My code is as follows (I have simplified it for ease of reading, sorry for the lack of functions): #include #include #include #include #include #include #include #include…
adrem7
  • 127
  • 2
  • 9
0
votes
2 answers

Arbitrary precision bit manipulation (Objective C)

I need to do bit operations on representations of arbitrary precision numbers in Objective C. So far I have been using NSData objects to hold the numbers - is there a way to bit shift the content of those? If not, is there a different way to achieve…
chm
  • 1,469
  • 12
  • 21
0
votes
1 answer

Arbitrary precision in c++ using Windows?

Is there a library that can be implemented relatively easily in windows? I made a few functions a while ago which used arrays of numbers to get the desired outcome. I might work at them when I get the time. But is there any such feature already…
Abcd
  • 57
  • 1
  • 4
0
votes
1 answer

numpy.allclose and multiprecision with mpmath

In my python code, I regularly verify some calculations using numpy.allclose. On the other hand, apart from these checks the implementation is able to deal with multiprecision (mpmath.mpc) numbers. If I want to run my verification code for the…
Anaphory
  • 5,456
  • 4
  • 33
  • 60
0
votes
1 answer

Which library should I use on OSX for arbitrary precision arithmetic?

I tried already GMP, MPFR. But I can't accomplish a simple division like below. BTW I have LLVM compiler in Xcode. I try to compile, run it to IOS Simulator. mpf_t a; mpf_init2 (a, 256); mpf_set_d(a, 0.7); mpf_t b; mpf_init2 (b, 256); mpf_set_d(b,…
János
  • 27,206
  • 24
  • 130
  • 270
1 2 3
19
20