1

While doing some calculations in Visual Studio C++ I found the final value of angle to be -1.#IND000000000000

What does this value mean? Has it gone out of scope? Following is the code I was trying to implement How do I calculate arc angle between two points on a circle? from this formula
cos-1 ((x1x2 + y1y2 + z1z2) / r2) as mentioned here

CODE

double x = vec1X * vec2X;
double y = vec1Y * vec2Y;
double r = sqrt(((vec2X - originX) * (vec2X - originX))+((vec2Y - originY) * (vec2Y - originY)));
angle = acos ((x + y) / r*r);

Sample values to reproduce error

vec1X = 91.094001770019531;
vec1Y = 147.74990844726562;
vec2X = 94.163322448730469;
vec2Y = 187.93711853027344;
originX = 136.79920959472656;
originY = 223.69624328613281;
Community
  • 1
  • 1
asloob
  • 1,308
  • 20
  • 34
  • Link to explanation of that particular NaN http://stackoverflow.com/questions/347920/what-do-1-inf00-1-ind00-and-1-ind-mean – CashCow Apr 17 '13 at 10:16

3 Answers3

3

That means the result is indeterminate; a more standard term is "not a number" or "NaN".

Possible reasons here are:

  • the argument to sqrt is negative
  • both operands of the division are zero
  • the argument to acos is outside the range [-1,1].

Any of these can happen due to floating-point rounding errors, even if mathematically they should not be possible; so you should always check values before passing them to functions with a limited input range.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
1

This is because acos argument should lie in [-1.0 .. 1.0], and your is not. For example if r is close to zero, you have big error. If you are sure , that input is ok, than, try to map values smaller than -1 to -1, and greater 1 to 1

kassak
  • 3,974
  • 1
  • 25
  • 36
1

It's a NaN value.

It actually means an "indeterminate" value, which means it could be "anything". Dividing 0 by 0 is an "indeterminate".

without calculating these, what is the value of the argument in acos? (It should be between -1 and 1)

Community
  • 1
  • 1
CashCow
  • 30,981
  • 5
  • 61
  • 92