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.

Filter by
Sorted by
Tagged with
39votes
6answers
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 ...
user avatar
30votes
2answers
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). ...
user avatar
  • 27.7k
24votes
1answer
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 ...
user avatar
  • 4,263
22votes
18answers
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?
user avatar
  • 6,914
20votes
5answers
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, ...
user avatar
  • 1,523
19votes
1answer
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 (...
user avatar
  • 27.7k
18votes
1answer
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" % (...
user avatar
18votes
1answer
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 ...
user avatar
  • 4,263
17votes
2answers
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 ...
user avatar
14votes
3answers
5kviews

Large numbers in Pascal (Delphi)

Can I work with large numbers (more than 10^400) with built-in method in Delphi?
user avatar
  • 263
14votes
5answers
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;...
user avatar
  • 977
14votes
7answers
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 ...
user avatar
  • 6,521
13votes
2answers
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 ...
user avatar
13votes
2answers
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 ...
user avatar
  • 42.4k
13votes
3answers
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 ...
user avatar
  • 318
12votes
3answers
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 ...
user avatar
  • 3,888
11votes
11answers
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 ...
user avatar
11votes
5answers
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 ...
user avatar
  • 7,346
11votes
3answers
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::...
user avatar
  • 458
11votes
1answer
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.
user avatar
  • 710
11votes
3answers
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 ...
user avatar
11votes
3answers
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 ...
user avatar
  • 4,263
10votes
2answers
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 ...
user avatar
  • 4,818
10votes
1answer
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 ...
user avatar
  • 8,134
9votes
3answers
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?
user avatar
  • 91
9votes
2answers
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 ...
user avatar
  • 301
9votes
2answers
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 ...
user avatar
  • 1,800
9votes
1answer
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 ...
user avatar
  • 654
8votes
3answers
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
user avatar
  • 8,285
8votes
6answers
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 ...
user avatar
  • 166
8votes
2answers
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 ...
user avatar
  • 25k
8votes
0answers
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 ...
user avatar
  • 255
7votes
2answers
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....
user avatar
7votes
8answers
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 ...
user avatar
  • 4,607
7votes
2answers
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 ...
user avatar
  • 19.1k
6votes
3answers
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 ...
user avatar
6votes
2answers
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 ...
user avatar
6votes
1answer
522views

SIMD versions of SHLD/SHRD instructions

SHLD/SHRD instructions are assembly instructions to implement multiprecisions shifts. Consider the following problem: uint64_t array[4] = {/*something*/}; left_shift(array, 172); right_shift(array, ...
user avatar
  • 53.2k
6votes
3answers
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 ...
user avatar
6votes
1answer
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 ...
user avatar
  • 2,004
5votes
5answers
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 ...
user avatar
  • 72.8k
5votes
3answers
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?
user avatar
  • 3,269
5votes
2answers
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: >> ...
user avatar
  • 109k
5votes
3answers
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 =...
user avatar
  • 85k
5votes
2answers
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 ...
user avatar
  • 1,043
5votes
2answers
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 ...
user avatar
  • 4,739
5votes
2answers
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 ...
user avatar
  • 71.6k
5votes
2answers
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 ...
user avatar
  • 303
5votes
2answers
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 ...
user avatar
5votes
2answers
613views

Boost multiprecision fails because the implementation of complex tries to cast to double in internal functions like _Isinf or _Isnan

I need a BSD-like licensed C(++) multiprecision library with complex numbers support so I tried boost. The following code fails: #include <boost/multiprecision/cpp_dec_float.hpp> #include <...
user avatar
  • 324

15 30 50 per page
1
2 3 4 5
7