Is there a simple way that i can manipulate high precision decimal numbers in java, without a limit on the number of decimal places, and the ability to output the number in a println or write it to a file? I want to work with one of the identities of PI that involves a sum of fractions, where k starts at 0 and goes to infinity. I know that most systems use limited decimals, but couldn't i use some pre-designed class which stores the value as a linked list of massive memory blocks if the number gets long enough? Please keep in mind i do need to do arithmetic with this class as well. Addition, subtraction, multiplication, and division should be sufficient.
0
votes
apfloat.org/apfloat_java if you don't mind using external libs.
– Jixi
For infinite precision you need infinite memory. Also calculations on infinite precision also takes an infinite amount of time.
– Peter Lawrey
Agreed. However, i guess the point here is that i would be using as much of my available memory as possible. :) Good point on the time, i suppose ill expect this to be a program to run in the background for quite a while!
– Drifter64
2 Answers
2
votes
Look at java.lang.BigDecimal, may solve your problem.
http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html