I’m trying to perform a power calculation in Java for exponent that is less than 1, for example: (2^0.333)
but when i calculate that in Java, i got a result with less precision than if i do the same calculation on a normal calculator.
in Java
double f = Math.pow(2.0,0.333);
System.out.println(f);
//output
//1.2596299799473993
in a normal calculator i got
//output
//1.2596299799473993502546921425703
how can I get the same result in java without losing precision?
any help is appreciated
Built-in floating point arithmetic in Java is of limited precision. The built-in
BigDecimalclass doesn’t provide the operations that you need (real exponentiation, or even logs). You can use a third-party app such as Apfloat (see theApfloatMathclass) or JScience, both of which can do the exponentiation calculation to arbitrary precision.