Alex Rivera | Logout

Why doesn't this crash? Aren't I dividing by zero here?

Asked 2009-09-19T18:00:39.297
14

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.

Edit
Report

1 Answer

1

Floating-point errors typically do not raise an exception.

answered 2009-09-19T18:06:59.387

Your Answer