Dan Joe
Dan Joe

Reputation: 17

ApfloatMath.pow method returns almost the correct value

Here is a sample code:

ApfloatMath.pow(new Apfloat(25, 5), new Apfloat(0.5, 5));

The above code performs the square root of 25.
This returns 4.9999.
I would've thought that this being arbitrary would return the correct value.

Upvotes: 0

Views: 55

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272497

From the Javadoc:

pow

Arbitrary power. Calculated using log() and exp().

In other words, this does something like exp(log(x) * y). However, log(25) is irrational, and thus has an infinite number of digits. Thus it has to be approximated at some point.

Upvotes: 0

Related Questions