Search code examples
javafloating-pointnanfloating-point-precision

Floating point - NaN


I am working on a research project on java in which some tough calculations have to be done. However I am done with most part but stuck at a point.. I have to calculate the following :

(2.1-2.3) raised to power 0.3.

But I get the answer NaN.. I have tried store result with both float and double variables, however it shows same result. Strangely when I did the same with a calculator , it showed result -0.430512

I can not figure out how to make it work with java
Code for same is:

Math.pow((provider1[k][a][m]-provider1[k][j][m]),prior[k][m]);. 

When the values of above are 2.1,2.3 and 0.3 - NaN is the output.

However when the values are 2.1, 2.3 and 3, it gets the correct value (-0.08). Can someone please help how to do this.


Solution

  • It must be an error. Check the calculator you are using.