Arithmetic operations on very long decimal places

I've always wondered: How can I perform arithmetic operations on very long decimal places - for example, calculating pi up to the 3000th decimal place (especially in an imperative language)?

0


source to share


3 answers


Use a language or library that supports arbitrary precision numbers ...?

In Python, ints will automatically advance to longs that are arbitrary sizes. You can use the second value to keep track of how many decimal places to move to get arbitrary floating point precision.



In Java, you can use the BigDecimal class , which is "arbitrary precision immutable decimal numbers".

I'm sure other examples exist in other languages.

+3


source


For languages ​​that don't support computation on bignums, there are often libraries. For example, you can look at GMP . The docs will provide you with pointers to some typical algorithmic approaches.



Making bigum arithmetic quickly is difficult, so there are some rather convoluted algorithms ...

+3


source


You either have to work with the data at the digit level (for example, calculate each digit gradually or deterministically), or define new data structures that have enough bits to provide adequate precision.

0


source







All Articles