[prev in list] [next in list] [prev in thread] [next in thread] 

List:       glibc-bug
Subject:    fetestexcept
From:       Jos van den Oever <oever () fenk ! wau ! nl>
Date:       2002-05-03 15:54:12
[Download RAW message or body]

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);
}

_______________________________________________
Bug-glibc mailing list
Bug-glibc@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-glibc
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic