/* * This program demonstrates a problem with FreeBSD/alpha's handling * of floating point exceptions. The exception flags are supposed to * be ``sticky'' in that arithmetic operations should only set flags, * never clear them. But when we trap into the kernel for operations * that are not supported in the hardware (such as underflow), all the * status flags are cleared. */ #include #include #include "fenv.h" #pragma STDC FENV_ACCESS ON int main(int argc, char *argv[]) { volatile double d; printf("Should be 00: %02x\n", fetestexcept(FE_ALL_EXCEPT)); /* Overflow + inexact */ d = DBL_MAX; d *= 2.0; printf("Should be 14: %02x\n", fetestexcept(FE_ALL_EXCEPT)); /* Underflow + inexact */ d = DBL_MIN; d /= DBL_MAX; printf("Should be 1c: %02x\n", fetestexcept(FE_ALL_EXCEPT)); /* Divide by zero */ d = 0.0; d = 1.0 / d; printf("Should be 1e: %02x\n", fetestexcept(FE_ALL_EXCEPT)); /* Overflow + inexact */ d = DBL_MAX; d *= 2.0; printf("Should be 1e: %02x\n", fetestexcept(FE_ALL_EXCEPT)); return (0); }