Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What programming languages support arbitrary precision arithmetic?

Tags:

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

like image 425
Matt Gregory Avatar asked Sep 27 '08 03:09

Matt Gregory


People also ask

Does Python has arbitrary precision arithmetic?

Some programming languages such as Lisp, Python, Perl, Haskell and Ruby use, or have an option to use, arbitrary-precision numbers for all integer arithmetic. Although this reduces performance, it eliminates the possibility of incorrect results (or exceptions) due to simple overflow.

What is arbitrary precision C++?

Arbitrary-Precision arithmetic, also known as "bignum" or simply "long arithmetic" is a set of data structures and algorithms which allows to process much greater numbers than can be fit in standard data types.

What is arbitrary integer in Python?

Python does have arbitrary precision integers. The number your code creates is not an integer. a mere python3 -c "print(999999999999999999999999 / 3)" would show you the issue immediately (it prints a float instead of integer).

What is variable precision arithmetic?

vpa( x ) uses variable-precision floating-point arithmetic (VPA) to evaluate each element of the symbolic input x to at least d significant digits, where d is the value of the digits function. The default value of digits is 32. example. vpa( x , d ) uses at least d significant digits, instead of the value of digits .


1 Answers

Some languages have this support built in. For example, take a look at java.math.BigDecimal in Java, or decimal.Decimal in Python.

Other languages frequently have a library available to provide this feature. For example, in C you could use GMP or other options.

The "Arbitrary-precision software" section of this article gives a good rundown of your options.

like image 147
Logan Avatar answered Oct 31 '22 21:10

Logan