I am trying to figure out a way to check for a undefined value of a slope in which case it would be vertical. I have tried using NULL but that doesn’t seem to work.
double Point::Slope(Point &p2)
{
double slop = 0;
slop = (y - p2.y) / (x - p2.x);
if (slop == NULL)
{
slop = 10e100;
}
return slop;
}
If you mean nan (‘not a number’) with “undefined”, you should avoid computing one in the first place, i.e. by checking that the denominator of a ‘/’ operation is not zero. Second, you can always check for nan by
see the man pages, or cppreference.