bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fetestexcept


From: Jos van den Oever
Subject: fetestexcept
Date: Fri, 3 May 2002 17:54:12 +0200

Hello glibc team,

I've also sent this report with glibcbug. If that arrived (I'm not sure of 
that) just ignore this email.

I'm using fenv.h to catch floating point exceptions. To identify them, I use 
fetestexcept. However this function always gives me 0.
I'm using glibc 

Here's the code:

#define _GNU_SOURCE 1
#include <signal.h>
#include <fenv.h>
#include <stdio.h>

void fpe_handler(int);

int main() {
        signal(SIGFPE, fpe_handler);
        if (fedisableexcept(FE_ALL_EXCEPT) == -1) {
                printf("could not disable exceptions.\n");
        }
        if (feenableexcept(FE_DIVBYZERO | FE_INVALID
                        | FE_UNDERFLOW | FE_OVERFLOW) == -1) {
                printf("could no enable exceptions.\n");
        }
        feclearexcept (FE_ALL_EXCEPT);

        double one = 1;
        double nul = 0;
        one /= nul;

        return 0;
}

void fpe_handler(int) {
        int e;
        printf("caught FPE, exiting.\n");
        e = fetestexcept(FE_ALL_EXCEPT);
        if (!e) {
                printf("no exception information set\n");
        }
        if (e & FE_DIVBYZERO) {
                printf("divide by zero\n");
        }
        if (e & FE_UNDERFLOW) {
                printf("underflow\n");
        }
        if (e & FE_OVERFLOW) {
                printf("overflow\n");
        }
        exit(1);
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]