   [fixed] why do i get a negative number from a square?
  hithis is my function:void getMagni(){magni=sqrt(this->dist[0]*this->dist[0]+this->dist[1]*this->dist[1]+this->dist[2]*this->dist[2]);   cout << magni << "\t"<<endl;}the weird thing is i often get "-1.#IND" which is "minus infinity" i believe(right?) from this function. how is this possible?magni is a sum of 3 squared(!) numbers, how can this ever be negative?it's the same story without the "sqrt". what am i doing wrong?edit: changed title because "sqrt" doesn't seem to be the problem[Edited by - back2newbelf on December 15, 2005 9:10:35 AM]
  You're doing an invalid calcuation somewhere which results in -1.#IND, check your dist values and see if they're all valid.  One or more of them may have been screwed up somewhere.Also why do you do this->dist[0] etc?  IMO it's simpler and more readable to just do dist[0] etc.   ;  i seem to be getting 1.#INF from alot of the "dist". could this be the problem? (it still shouldn't become negative, no)?   ;Quote:Original post by back2newbelfi seem to be getting 1.#INF from alot of the "dist". could this be the problem? (it still shouldn't become negative, no)?Yes, I would bet that that is the problem.Numbers are stored in a kinda funky way in computers.  To save space, extra information can be built right into the number.  For example, if the number is "infinity," the bits of the number in memory are rearranged slightly so that the computer can tell that the number is "infinity."  These rearrangements are NOT consistent with the normal order of things and consequently applying math functions (e.g. * and +) doesn't work as you might expect all the time.  And anyway... what would you expect from infinity * infinity?At any rate, if your distances are coming out as 1.#INF, you have a bug there first.   ;  well "dist" was the distance in which a ray hits a infite plane (which cuts the sceen in half, from the right). some points (those in the middle of the screen) really do hit the plane in *very* far distance, too big for float i would guess.fixed the problem with:if(magni<=0)magni= *some huge number*;   