I’ve always been curious: how can I perform arithmetic operations on very long decimals–for example, calculating pi to the 3000th decimal place (especially in an imperative language)?
I’ve always been curious: how can I perform arithmetic operations on very long decimals–for
Share
Use a language or library that supports arbitrary precision numbers…?
In Python, ints will auto-promote to longs which are arbitrary size. You could use a second value for keeping track of how many decimals to shift over by to get a sort of arbitrary precision floating point.
In Java you could use the BigDecimal class, which represents “Immutable, arbitrary-precision signed decimal numbers”.
I’m sure other examples exist in other languages.