ArithmeticException thrown during BigDecimal.divide

后端 未结 9 670
渐次进展
渐次进展 2020-11-30 08:41

I thought java.math.BigDecimal is supposed to be The Answer™ to the need of performing infinite precision arithmetic with decimal numbers.

Consider the followi

9条回答
  •  攒了一身酷
    2020-11-30 08:54

    Notice we are using a computer... A computer has a lot of ram and precision takes ram. So when you want an infinite precision you need
    (infinite * infinite) ^ (infinite * Integer.MAX_VALUE) terrabyte ram...

    I know 1 / 3 is 0.333333... and it should be possible to store it in ram like "one divided by three" and then you can multiply it back and you should have 1. But I don't think Java has something like that...
    Maybe you have to win the Nobel Price for writing something doing that. ;-)

提交回复
热议问题