Skip to main content
gamedev.net
🔒 Locked

a -1.#IND problem

Started by billconan 3 replies 1.5k views
Original Post
billconan
billconan
hello guys, my program crashes, because some of the floats have a value of -1.#IND i know it is a symbol for infinity and probably caused by overflow. but my question is how to debug this error. i want to add some lines in the code like: if(value==-1.#IND) ... therefore, i can identify the location where the wrong value is computed. however, it seems that the compiler i'm using, which is visual studio 2008, doesn't recognize "-1.#IND" so i don't know how to do this. please help. thank you very much.
RealMarkP
RealMarkP
You can try the following functions from the math.h header. But in reality, you should be checking your math so that it doesn't divide by zero (or something similar).
------------Anything prior to 9am should be illegal.
billconan
billconan
Quote:
Original post by RealMarkP
You can try the following functions from the math.h header. But in reality, you should be checking your math so that it doesn't divide by zero (or something similar).


thank you. i'm not sure if the problem was caused by a division by zero. i need to identify the location of the problem. thank you.

Giedrius
Giedrius
There's a way to check for invalid numbers. It looks strange, but it does work:

if (x != x)
{
...
}

I remember I once had a very simillar problem, it was caused by acosf and floating point imprecision. I was giving acosf value 1.0000000001f and it returned -1.#IND. To fix it, I simply clamped the input to acosf to the range [0;1].
billconan
billconan
Quote:
Original post by Giedrius
There's a way to check for invalid numbers. It looks strange, but it does work:

if (x != x)
{
...
}

I remember I once had a very simillar problem, it was caused by acosf and floating point imprecision. I was giving acosf value 1.0000000001f and it returned -1.#IND. To fix it, I simply clamped the input to acosf to the range [0;1].



i do use acosf, and maybe that is also my problem.

thank you.

and for some reason, there is no isinf function in my math.h

i see this:

#if defined(_M_AMD64)
_CRTIMP int __cdecl _isnanf(_In_ float _X);
#endif /* _M_AMD64 */

this is odd. only amd64 needs check "not a number"?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.