Answer the question
In order to leave comments, you need to log in
Why am I getting Nan as a result of the function?
Good afternoon!
Happy holidays everyone!
I write such a return in a function
return x = (double)Gdx.graphics.getWidth()/2+Math.sqrt((85*85)-(y+(double)Gdx.graphics.getHeight()/2)*(y+(double)Gdx.graphics.getHeight()/2));
Answer the question
In order to leave comments, you need to log in
I think because (85*85) < (y+(double)Gdx.graphics.getHeight()/2)*(y+(double)Gdx.graphics.getHeight()/2
Which, in general, is logical, if it is the height of the screen.So the root of a negative number is a complex number, and Math.sqrt legitimately returns NaN.All further calculations with NaN return NaN.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question