Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is '-1.#IND'?

I have some code that will allow me to draw a crescent moon shape, and have extracted the values to excel to be drawn. However in place of some numbers, there is -1.#IND in place. Firstly if anyone could explain what this means, as Google came back with 0 links. And secondly if there is anyway to stop it from occurring.

There is a brief analogy of my code. I have lots more code besides this, however that is just calculating angles.

for(int j=0; j<=n; j++)//calculation for angles and output displayed to user
{
    Xnew2 = -j*(Y+R1)/n; //calculate x coordinate
    Ynew2 = Y*(pow(1-(pow((Xnew2/X),2)),0.5));
    if(abs(Ynew2) <= R1)
        cout<<"\n("<<Xnew2<<", "<<Ynew2<<")"<<endl;
}

MORE INFO

I'm now having the problem with this code.

for(int i=0; i<=n; i++) //calculation for angles and output displayed to user
{                                          
    Xnew = -i*(Y+R1)/n; //calculate x coordinate
    Ynew = pow((((Y+R1)*(Y+R1)) - (Xnew*Xnew)), 0.5); //calculate y coordinate

AND

for(int j=0; j<=n; j++)//calculation for angles and output displayed to user
{
    Xnew2 = -j*(Y+R1)/((n)+((0.00001)*(n==0))); //calculate x coordinate
    Ynew2 = Y*(pow(abs(1-(pow((Xnew2/X),2))),0.5));
    if(abs(Ynew2) <= R1)
        cout<<"\n("<<Xnew2<<", "<<Ynew2<<")"<<endl;

I am having the problem drawing the crescent moon that I cannot get the two circles to have the same starting point? If this makes sense, I am trying to get two parts of circles to draw a crescent moon as such that they have the same start and end points. The only user input I have to work by is the radius and chosen center point.

If anyone has any suggestions on how to do this, it would be great, currently all I am getting more a 'half doughnut' shape, due to the circles not being connected.

like image 410
Rory Duncan Avatar asked Sep 16 '25 23:09

Rory Duncan


2 Answers

#IND means an indetermined form.

What you have there is something known as 'Not a number' or NaN for short.

Quoting from Wikipedia, generation is done by:

  • Operations with a NaN as at least one operand.
  • The divisions 0/0 and ±∞/±∞
  • The multiplications 0×±∞ and ±∞×0
  • The additions ∞ + (−∞), (−∞) + ∞ and equivalent subtractions
  • The square root of a negative number.
  • The logarithm of a negative number
  • The inverse sine or cosine of a number that is less than −1 or greater than +1.

You're doing at least one of those things.

Edit:

After analyzing your code, these are 2 possibilities:

  • When n == 0 in the first iteration where j == 0 too, Xnew2 will be -1.#IND
  • When Xnew2 is greater than X, Ynew2 will be complex -> NaN
like image 164
user123 Avatar answered Sep 19 '25 09:09

user123


You are doing something illegal to a floating point number, such as taking the square root of a negative number. This is presumably on Windows. On Linux, you would get NaN (not a number) or inf. See -1 #IND Question for further information; the link provided in the second answer is helpful.

like image 37
Muscles Avatar answered Sep 19 '25 11:09

Muscles