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
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
  • 409
  • 1
  • 4
  • 11
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
  • 388
  • 1
  • 3
  • 14
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,519
  • 13
  • 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
  • 6,045
  • 4
  • 37
  • 68
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
  • 32,867
  • 38
  • 193
  • 353
-1
votes
2 answers

Double precision and quadruple precision in MATLAB

I want to convert data(double precision,15 decimal points) to data of another type(quadruple precision,34 decimal points). So, I used vpa function like this: data = sin(2*pi*frequency*time); quad_data = vpa(data,34); But, the type of the result is…
-1
votes
1 answer

Divide arbitrary binary integers by 3 in python

All the binary integers am given are always divisible by 3 so no floating-point values involved. The return value must also be a binary string Tried this but a and h are different yet they should be >>>…
Mpiima
  • 13
  • 4
-1
votes
1 answer

gmp for R and other sols

implemented a solution to a problem in arithmetic precision handeling in gmp - but the results are rather strange . as a part of troubleshooting I was wondering whether there is any other package hich woudl allow similar operatiosn as gmp in R. I…
heineman
  • 25
  • 6
-1
votes
4 answers

C++ pow() function produces arbitrarily precise result

If double precision does not guarantee more than 16 significant decimal digits, how is such an output generated by this standard C++ program? Also small value change operations done on "ans" such as ++ans don't alter the screen output. Is the answer…
-2
votes
2 answers

How to convert large HEX string to INT in C

I got large HEX string in result into int i could be more than 10 ^ 30, and I converted in hex. I need sum (3 hex string) and remove last 12 numbers. hex example "000000000000000000000000bd4c61f945644cf099d41ab8a0ab2ac5d2533835",…
-2
votes
1 answer

Why does Python floor division return a float when the divisor and/or dividend is a float?

If I understand correctly, the return value for floor division is always a whole number, even if the dividend and/or divisor are not whole numbers, so why does it not always return an integer. It's detrimental in my case because converting from a…
-2
votes
3 answers

Why does the program ends even before running?

I want to use this question to improve a bit in my general understanding of how computer works, since I'll probably never have the chance to study in a profound and deep manner. Sorry in advance if the question is silly and not useful in general,…
RenatoRenatoRenato
  • 317
  • 1
  • 3
  • 13
-3
votes
1 answer

How to implement bignum addition/multiplication from scratch in C++

I have started writing a bignum library, with a vector of shorts to represent the value, a print function, and negative number support. However, I cannot find a good way to implement long addition, like this: 123 +123 ---- 246 The latest code I…
built1n
  • 1,518
  • 14
  • 25
1 2 3
21
22