No, The result you are getting is not a error at all. Function is returning value NaN means Not a Number
.
This function executes some underlying system algorithm and return value NaN.
To help ensure portability of Java programs, the definitions of
some of the numeric functions in this package require that they
produce the same results as certain published algorithms. These
algorithms are available from the well-known network library
netlib
as the package "Freely Distributable Math
Library," fdlibm
. These
algorithms, which are written in the C programming language, are then
to be understood as executed with all floating-point operations
following the rules of Java floating-point arithmetic.
Please refer this answer for more details.
About
So, should I write it is runtime error or just write NaN in the value?
It's up to you or requirement. If you are using this value in further calculations you should handle this case very carefully.
May be return zero if NaN could be a solution.