What does -1.#IND mean?

Started by
8 comments, last by Sneftel 17 years, 2 months ago
When I print out a float to screen, that is supposed to be the degrees in radians between two vectors, I get -1.#IND, what could it mean? I thought maybe it means that the function that I used to compute it returned an imaginary number and thats how its displaying it, I couldn't find anything online on it. Thnx for replies.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Advertisement
It means you've done something unlegal with the float, most likely there's a divide by zero you're missing somewhere. If you post the code (both calculating the angle as well as printing), we can help catch it and suggest a safer alternative.

-jouley

[Edit: Actually, dividing by zero yields a "1.#INF" error (emphasis mine). This points out that "1.#IND" is caused by trying to performing trigonometric operations on a number that's out of range (like acos(2.3f)).]

[Edit 2: Actually, dividing zero by zero yields a "-1.#IND" error (thanks, miodragsm!). My money's still on an illegal trig operation, though.]
This means that the variable is not a number (NaN). This could be caused by using an unitialized variable or possibly dividing by zero.
It's 0.0f/0.0f result. Try this :

float a=0,b=0;
float c=a/b;

I tried this in VC8 and got -1.#IND000.
This is the parts of the source that I use to compue the angle between 2 vects.
Like Mr.Awesome said theres the value procuced for acos() is probably greater than 1.

BALL_angle += MXMATH::AngleBetweenVectors(spherePoint, nowPoint);float MXMATH::AngleBetweenVectors(D3DXVECTOR3  v1, D3DXVECTOR3  v2){	return (float)(acos( (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z)/(Vect3DLength(v1)*Vect3DLength(v2)) ));}float MXMATH::Vect3DLength(D3DXVECTOR3 v){	return (float)sqrt( sqr(v.x) + sqr(v.y) + sqr(v.z) );}

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

You should probably check that your argument to acos is in the interval [-1, 1]. Even a small amount outside this range will cause a NaN.
You may want to look into the atan2(float y, float x) function. It'll get the quadrant correct for you, and can take any sort of input (except (0, 0)).
Usage, where point1 = x1, y1 and point2 = x2, y2:float fAngle = atan2(y2 - y1, x2 - x1);
You can also get it by square rooting a negative number, but that shouldn't be happening in the code you posted.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
Thanks for replies guys, I appreciate the help. Im just gonna check the input for acos() to make sure its not greater than 1 or less than -1. Thanks again.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Quote:Original post by VanillaSnake21
Thanks for replies guys, I appreciate the help. Im just gonna check the input for acos() to make sure its not greater than 1 or less than -1. Thanks again.

Don't do that. At values close to 1 or -1, even those which don't look out of range, strange things can happen. acos is not a good way to find the angle between vectors.

For 3D vectors, the best way is atan2(dot(v1,v2), magnitude(cross(v1,v2))). This is robust and well-behaved under all circumstances.

This topic is closed to new replies.

Advertisement