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

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


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


Divide by zero error only happens for integer division.For float, normally you get infinity, unless the dividend is zero.


Floating-point errors typically do not raise an exception.