K
K
krembrule20162019-05-14 19:30:22
Java
krembrule2016, 2019-05-14 19:30:22

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));

In response I get Nan
I apologize for the stupid question, I just usually get stupid for a long time with this kind of error.
Chiadnt?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-05-14
@krembrule2016

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 question

Ask a Question

731 491 924 answers to any question