Evening. I’ve got a question regarding base-16 computations in Java. I’m looking to compute pi with a reasonable algorithm to N digits with some constraint to the number of digits allowed (thinking something like 15-20). Eventually this will just be one function of a calculator later.
I’m not looking for ridiculous levels of precision, nor do I want help with the algorithm. I’m aware that there is a magic API method for it, but I’d rather do it myself.
The formula: Bailey–Borwein–Plouffe formula. From what I understand, it computes pi in hexadecimal.
So, what’s my issue? I’m not that good at Java. The classes I’ve taken (up to and including Data Structures) really only used the languages I know as a means to an end, without focusing on anything language-specific. I want to compute pi to the nth digit in hexadecimal, then convert that value to a String for display purposes.
Any suggestions on where to start with that? My experience with coding in java is about 20 weeks, and what I’m stuck on seems to be a Java-specific thing.
If I’m wrong anywhere, by all means point it out. I’m here to learn.
I would implement your current algorithim using
BigDecimalfirst. When this works to your satisfaction you can look at replacing the functionality BigDecimal provides (assuming you want to write your own)