Thread: What does "nan" mean?

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    28

    Post What does "nan" mean?

    My program has a matrix of floating point values, after I performed calculations to each element in the matrix, when I print out using printf() some of the elements turned out to have the value "nan", what does nan mean?

    My code is as follows:
    Code:
    float local_force[M][N];
            /* compute the forces on each of the N particles on each processor */
            for (i = 0; i < M; i++) {
                    for (j = 0; j < N; j++) {
                            if ( recv_xPos[i] == xPos[j] &&  recv_yPos[i] == yPos[j])
                                    local_force[i][j] = 0;             /* 0 represent infinite force in newton */
                            else
                            {
                                    float xDis = absolute(recv_xPos[i] - xPos[j]);
                                    float yDis = absolute(recv_yPos[i] - yPos[j]);
                                    radius_square = pow(xDis, 2) + pow(yDis, 2);
                                    local_force[i][j] = (recv_charge[i] * charge[j]) / radius_square;
                            }
                    }
            }
    Please use [code][/code]Tags

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    28
    Thanks, this is what I needed. yeah!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "nan" output error
    By Oliveira in forum C Programming
    Replies: 6
    Last Post: 07-06-2009, 02:07 PM
  2. Help with "nan" for my output
    By bigparker in forum C Programming
    Replies: 21
    Last Post: 06-16-2009, 07:14 AM