# 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.

303 questions
Filter by
Sorted by
Tagged with
33kviews

### What class to use for money representation?

What class should I use for representation of money to avoid most rounding errors? Should I use Decimal, or a simple built-in number? Is there any existing Money class with support for currency ...
3kviews

### What is the fastest way to calculate e to 2 trillion digits?

I want to calculate e to 2 trillion (2,000,000,000,000) digits. This is about 1,8 TiB of pure e. I just implemented a taylor series expansion algorithm using GMP (code can be found here). ...
5kviews

### Can long integer routines benefit from SSE?

I'm still working on routines for arbitrary long integers in C++. So far, I have implemented addition/subtraction and multiplication for 64-bit Intel CPUs. Everything works fine, but I wondered if I ...
11kviews

### What programming languages support arbitrary precision arithmetic?

What programming languages support arbitrary precision arithmetic and could you give a short example of how to print an arbitrary number of digits?
19kviews

### numpy arbitrary precision linear algebra

I have a numpy 2d array [medium/large sized - say 500x500]. I want to find the eigenvalues of the element-wise exponent of it. The problem is that some of the values are quite negative (-800,-1000, ...
965views

### How to multiply terabyte-sized numbers?

When multiplying very large numbers, you use FFT based multiplication (see Schönhage–Strassen algorithm). For performance reason I'm caching the twiddle factors. The problem is for huge numbers (...
12kviews

### Is Python incorrectly handling this "arbitrary precision integer"?

Python is supposed to have "arbitrary precision integers," according to the answer in Python integer ranges. But this result is plainly not arbitrary precision: \$ python -c 'print("%d" % (...
6kviews

### AVX VMOVDQA slower than two SSE MOVDQA?

While I was working on my fast ADD loop (Speed up x64 assembler ADD loop), I was testing memory access with SSE and AVX instructions. To add I have to read two inputs and produce one output. So I ...
5kviews

### Arbitrary-Precision Math in PHP

I'm currently trying to figure out how to work with arbitrary-precision numbers in PHP. So I guess my first question would be what exactly is arbitrary-precision math. I tried Googling for a good ...
5kviews

### Large numbers in Pascal (Delphi)

Can I work with large numbers (more than 10^400) with built-in method in Delphi?
3kviews

### PHP gives incorrect results when formatting long numbers

I am working with huge numbers for website purposes and I need long calculation. When I echo a long number I don't get the correct output. Example // A random number \$x = 100000000000000000000000000;...
3kviews

### How to work on big integers that don't fit into any of language's data structures

I'm trying to solve a programming contest's preliminary problems and for 2 of the problems I have to calculate and print some very big integers(like 100!, 2^100). I also need a fast way to calculate ...
1kviews

### Exact real arithmetic and lazy list performance in C++/Haskell

I recently came across the subject of exact real arithmetic after reading this paper and this paper. I have found a number of papers that discuss realizations of exact arithmetic using signed digit ...
303views

### Compute the product a * b² * c³ ... efficiently

What is the most efficient way to compute the product a1 b2 c3 d4 e5 ... assuming that squaring costs about half as much as multiplication? The number of operands is less than 100. Is there a ...
5kviews

### Handle arbitrary length integers in C++

Can someone tell me of a good C++ library for handling (doing operations etc...) with arbitrarily large numbers (it can be a library that handles arbitrary precision floats too, but handling integers ...
2kviews

### Spreadsheet calculations with (at least) the accuracy of a C double

I was doing some calculations for planning an improved implementation of my prime sieve when I noticed that the Libre Office spreadsheet was showing the wrong values for numbers far below 2^53, which ...
8kviews

### What is the sum of the digits of the number 2^1000?

This is a problem from Project Euler, and this question includes some source code, so consider this your spoiler alert, in case you are interested in solving it yourself. It is discouraged to ...
3kviews

### Floats vs rationals in arbitrary precision fractional arithmetic (C/C++)

Since there are two ways of implementing an AP fractional number, one is to emulate the storage and behavior of the double data type, only with more bytes, and the other is to use an existing integer ...
10kviews

### Convert large hex string to decimal string

I need to convert a large (too large for the built-in data types) hex string to a string with it's decimal representation. For example: std::string sHex = "07AA17C660F3DD1D2A1B48F1B746C148"; std::...
5kviews

### What's the best (for speed) arbitrary-precision library for C++? [duplicate]

I need the fastest library that is available for C++. My platform will be x86 and x86-64 which supports floating points.
3kviews

### Is there an arbitrary precision floating point library for C/C++ which allows arbitrary precision exponents?

I'm looking for an arbitrary precision floating point library for C/C++ (plain C is preferred). I need arbitrary precision exponents. GMP and MPFR use fixed size exponents, so they are ineligible (I ...
1kviews

### Speed up x64 assembler ADD loop

I'm working on arithmetic for multiplication of very long integers (some 100,000 decimal digits). As part of my library I to add two long numbers. Profiling shows that my code runs up to 25% of it's ...
273views

### How can I set the level of precision for Raku's sqrt?

With Perl, one could use bignum to set the level of precision for all operators. As in: use bignum ( p => -50 ); print sqrt(20); # 4.47213595499957939281834733746255247088123671922305 With ...
2kviews

### Go Protobuf Precision Decimals

What is the correct scalar type to use in my protobuf definition file, if I want to transmit an arbitrary-precision decimal value? I am using shopspring/decimal instead of a float64 in my Go code to ...
7kviews

### How to add 2 arbitrarily sized integers in C++?

I would like to add 2 arbitrarily sized integers in C++. How can I go about doing this?
1kviews

### Converting an arbitrary-precision rational number (OCaml, zarith) to an approximate floating number

I'm using the Zarith library to do arbitrary-precision rational arithmetic. Suppose I have a rational number q of type Q.t that is the ratio of two big integers (Q is Zarith's arbitrary-precision ...
3kviews

### JVM Arbitrary Precision Libraries

I'm working on a project ( in Scala ), where I have a need to manipulate some very large numbers; far too big to be represented by the integral types. Java provides the BigInteger and BigDecimal ...
1kviews

### Get GCC To Use Carry Logic For Arbitrary Precision Arithmetic Without Inline Assembly?

When working with arbitrary precision arithmetic (e.g. 512-bit integers), is there any way to get GCC to use ADC and similar instructions without using inline assembly? A first glance at GMP's ...
8kviews

### How to generate random 64-bit value as decimal string in PHP

Oauth requires a random 64-bit, unsigned number encoded as an ASCII string in decimal format. Can you guys help me achieve this with php? Thanks
830views

### Python computing error

I’m using the API mpmath to compute the following sum Let us consider the serie u0, u1, u2 defined by: u0 = 3/2 = 1,5 u1 = 5/3 = 1,6666666… un+1 = 2003 - 6002/un + 4000/un un-1 The serie ...
4kviews

### What is the precise meaning of arbitrary precision?

This might be a very simple question for some but I would like to know the meaning of arbitrary precision which appears in the first line in JavaDoc of BigInteger : Immutable arbitrary-precision ...
4kviews

### How should the MySQL Decimal datatype be used in php? [duplicate]

Hopefully just a quick question. I have a DECIMAL column in my database. The value is a very small decimal fraction - summing this value for all rows would equal 1. Now I'd like to use this value in ...
2kviews

### How can I use arbitrary length integers in Perl?

Is there any standard way to use integers of arbitrary length in Perl? I am working on code that generates x64 assembly for tests, and I'm tired of manipulating 32 bits at a time. I'm using Perl 5....
968views

### Has arbitrary-precision arithmetic affected numerical analysis software?

Has arbitrary-precision arithmetic affected numerical analysis software? I feel that most numerical analysis software keeps on using the same floats and doubles. If I'm right, I'd love to know the ...
2kviews

### Fractions with decimal precision

Is there a pure python implementation of fractions.Fraction that supports longs as numerator and denominator? Unfortunately, exponentiation appears to be coded in to return a float (ack!!!), which ...
424views

### Number type boundaries in Common LISP and Stack flowing over in GHCI

First question ever here, and newbie in both Common LISP and Haskell, please be kind. I have a function in Common LISP - code below - which is intended to tell whether the area of a triangle is an ...
1kviews

### Hash an arbitrary precision value (boost::multiprecision::cpp_int)

I need to get the hash of a value with arbitrary precision (from Boost.Multiprecision); I use the cpp_int backend. I came up with the following code: boost::multiprecision::cpp_int x0 = 1; const auto ...
522views

### SIMD versions of SHLD/SHRD instructions

SHLD/SHRD instructions are assembly instructions to implement multiprecisions shifts. Consider the following problem: uint64_t array = {/*something*/}; left_shift(array, 172); right_shift(array, ...
232views

### How to determine before hand if an unsigned calculation may possibly overflow?

As a personal project I am working on implementing an Arbitrary Precision number type for a pet project of mine. I already know about all the popular, tested and robust libraries out there that do ... 123views

### Can I use a `mpfr_t` as both input and output argument?

The question is very simple and direct, but I could not find an answer on the documentation. If I have mpfr_t a, b; Can I do something like mpfr_add(a, a, b, rnd); This would compute the sum of a ...
2kviews

### Arbitrary precision arithmetic with Ruby

How the heck does Ruby do this? Does Jörg or anyone else know what's happening behind the scenes? Unfortunately I don't know C very well so bignum.c is of little help to me. I was just kind of ...
4kviews

### Is there support for arbitrary precision arithmetic in C#?

Does C# support arbitrary precision arithmetic (I think this is also called bignums)? If it doesn't, which libraries do support it?
604views

### Obtain first significant digits of a number using variable-precision arithmetic

Assume you want to know the first W significant digits of a number, say pi, using vpa. Simply calling vpa with that many digits does not work. Consider the following example with W = 35: >> ...
2kviews

### Restore a number from several its remainders (chinese remainder theorem)

I have a long integer number, but it is stored not in decimal form, but as set of remainders. So, I have not the N number, but set of such remainders: r_1 = N % 2147483743 r_2 = N % 2147483713 r_3 =...
306views

### when extending python with c, how do one cope with arbitrary size integers?

The Python/C API manual mentions conversion functions from⁽¹⁾ and to⁽²⁾ void pointers, which seem to be the only way to use arbitrary length python integers in C. (1) : PyLong_FromVoidPtr() and ...
1kviews

### What is the fastest semi-arbitrary precision math library? [closed]

I'm using long double in a C program to compute 2D images of the Mandelbrot Set but wish to have further precision to zoom deeper. Are there any performance gains to be had from an arbitrary ...
271views

### manually printing a N-byte integer

What is a scalable algorithm to print an N-binary-digit integer manually whose value does not fit in long long. I know printf and friends, along with <iostream> (which most likely piggy-backs on ...
525views

### Redis support arbitrary precision in LUA Scripts

I need to be able to make a transaction in redis that does the following: decrement n value if and only if the result is > 0 otherwise, do nothing deal with arbitrary precision decimal numbers (I ...
993views

### Why do BigInteger implementations use sign-magnitude instead of two's complement?

Arbitary-precision signed integers are almost always implemented using a sign-magnitude representation: (Java) BigInteger in OpenJDK (Python) Bigint implementation of the Python built-in int type in ...