4.59 About trapping software floating-point division-by-zero errors

Software floating-point division-by-zero errors can be trapped with the __ieee_status intrinsic.

__ieee_status(FE_IEEE_MASK_ALL_EXCEPT, FE_IEEE_MASK_DIVBYZERO);
This traps any division-by-zero errors in code, and untraps all other exceptions, as illustrated in the following example:
#include <stdio.h>
#include <fenv.h>
int main(void)
{    float a, b, c;
    // Trap the Invalid Operation exception and untrap all other
    // exceptions:
    __ieee_status(FE_IEEE_MASK_ALL_EXCEPT, FE_IEEE_MASK_DIVBYZERO);
    c = 0;
    a = b / c;
    printf("b / c = %f, ", a); // trap division-by-zero error
    return 0;
}
Related concepts
4.58 Software floating-point division-by-zero errors in C code
4.60 Identification of software floating-point division-by-zero errors
4.61 Software floating-point division-by-zero debugging
Related information
__ieee_status()
Non-ConfidentialPDF file icon PDF versionARM DUI0375E
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.