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

Matlab high precision calculation in c++ via mex files

I want to learn how to do high precision calculations of a (Matlab) function in C++ via mex files – how to define new types if required, and what requirements / installations / makes I need. I am pretty new (again) to C++ and have Windows 7 and g++…
Futurist
  • 75
  • 1
  • 8
0
votes
1 answer

Numeric Precision Rounding Artifacts with PostgreSQL

We have an application that is attempting a bulk insert into a table within a postgresql (9.1 I think, I don't have access helping coworker troubleshoot remotely). A trace shows the raw values are generated correctly and handed off to the ODBC…
cjweitz
  • 33
  • 2
  • 9
0
votes
2 answers

Laguerre polynomials in python using scipy, lack of convergence?

The laguerre polynomials don't seem to be converging at some orders as can be demonstrated by running the following code. import numpy as np from sympy import mpmath as mp from scipy.special import genlaguerre as genlag from sympy.mpmath import…
evan54
  • 3,585
  • 5
  • 34
  • 61
0
votes
1 answer

Phpunit and floating point numbers stored as strings

I'm currently using BC Math extension in a project. In my unit tests there are some comparisons that would be similar to the below: This will pass: $this->assertEquals('1.23456789123456789123434', …
Purple Hexagon
  • 3,538
  • 2
  • 24
  • 45
0
votes
2 answers

Arbitrary Precision Numbers, Google App Engine, Python, NDB

As an academic exercise, I am trying to achieve an arbitrary precision (call it AP) system in google app engine using python and the NDB storage. I know that there are AP libraries out there so we can skip that. I am curious how one might store the…
0
votes
1 answer

mpfr(0.5) invalid floating point operation

I hope I am not pointing out something obvious, or that the fix to this is not obvious. I am using gmpy2 2.0.3 on a 64 bit windows 7 machine, coding with PyScripter. The following code gives an "Invalid floating point operation" error, from gmpy2…
0
votes
0 answers

Converting decimal to different bases

I'm writing a program to compute the conversion of number system. My goal is to let the program compute very large number at a short time (<0.1s) and I made a NSString category to let me compute very large number (+ - * / %), a function to convert…
PlusA
  • 545
  • 1
  • 6
  • 15
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
  • 18,047
  • 15
  • 98
  • 153
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
  • 341
  • 1
  • 2
  • 15
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
  • 604
  • 6
  • 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
  • 4
  • 11
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
  • 4,177
  • 14
  • 53
  • 85