I’m getting the slope of a line bounded by two points
float slopeXY(CGPoint p1, CGPoint p2)
{
return ((p2.y - p1.y) / (p2.x - p1.x));
}
If I give it a zero-sized line,
CGPoint p1 = CGPointMake(0, 10);
CGPoint p2 = CGPointMake(0, 10);
float sxy = slopeXY(p1, p2);
I don’t get a divide by zero error.
With the default floating-point environment on OS X, floating-point division by zero does not cause a trap or exception. 0.0/0.0 will instead return a NaN and raise the invalid floating-point status flag in the fpscr. Dividing a non-zero value by 0.0 will return an infinity and raise the divide-by-zero flag.
You can check for these conditions, if you need to, using the isnan( ) and isinf( ) functions defined in math.h