[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feholdexcept() does not seem to clear the exception flags correctly
From: |
Bernard WEISSER |
Subject: |
feholdexcept() does not seem to clear the exception flags correctly |
Date: |
Mon, 07 Feb 2005 22:12:04 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040618 |
Hello,
I used the feholdexcept() function and it does not seem to follow
exactly the behaviour described in the "fenv" man page.
My configuration is :
gcc version 3.3.4
glibc-2.3.2-i486-6
Linux mars 2.4.26 #6 Mon Jun 14 19:07:27 PDT 2004 i686
>Release: libc-2.3.2
>Environment:
<machine, os, target, libraries (multiple lines)>
Host type: i486-slackware-linux-gnu
System: Linux mars 2.4.26 #6 Mon Jun 14 19:07:27 PDT 2004 i686 unknown
unknown GNU/Linux
Architecture: i686
Addons: linuxthreads
Build CFLAGS: -g -O2 -march=i486 -mcpu=i686
Build CC: i486-slackware-linux-gcc
Compiler version: 3.3.3
Kernel headers: 2.4.26
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no
Here is the code :
/*
* Execution gives that output :
*
* at start, we have :
* no exception flags are set
* no traps are enabled
* --
* after raising FE_INVALID exception, we have :
* invalid operation flag set
* no traps are enabled
* --
* after enabling FE_DIVBYZERO trap, we have :
* invalid operation flag set
* division by zero trap enabled
* --
* saving environment
* after saving environment, we have :
* invalid operation flag set <===== should be cleared
* no traps are enabled
* --
*
* Manual page "fenv.h" says that calling "feholdexcept()" clears all
exceptions
* flags and sets a non-stop (continue on exceptions) mode, if available.
*
* What I see here is that the non-stop mode is correctly set, but that
* exception flags ARE NOT RESET.
*/
#define _GNU_SOURCE /* pour feenableexcept */
#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>
static void print_fe(void)
{
int flags ;
int traps ;
flags = fetestexcept (FE_ALL_EXCEPT) ;
traps = fegetexcept () ;
if (flags & FE_INEXACT) printf(" inexact result flag set\n");
if (flags & FE_UNDERFLOW) printf(" underflow flag set\n");
if (flags & FE_OVERFLOW) printf(" overflow flag set\n");
if (flags & FE_DIVBYZERO) printf(" division by zero flag set\n");
if (flags & FE_INVALID) printf(" invalid operation flag set\n");
if (!(flags & FE_ALL_EXCEPT)) printf(" no exception flags are set\n");
if (traps & FE_INEXACT) printf(" inexact result trap enabled\n");
if (traps & FE_UNDERFLOW) printf(" underflow trap enabled\n");
if (traps & FE_OVERFLOW) printf(" overflow trap enabled\n");
if (traps & FE_DIVBYZERO) printf(" division by zero trap enabled\n");
if (traps & FE_INVALID) printf(" invalid operation trap
enabled\n");
if (!(traps & FE_ALL_EXCEPT)) printf(" no traps are enabled\n");
printf (" --\n") ;
}
int main(void)
{
fenv_t holdenv;
/* Env initial value */
printf("at start, we have :\n");
print_fe();
/* Raise FE_INVALID exception */
feraiseexcept(FE_INVALID) ;
printf("after raising FE_INVALID exception, we have :\n");
print_fe() ;
/* Enable FE_DIVBYZERO trap */
if (feenableexcept(FE_DIVBYZERO) == -1) {
fprintf (stderr, "feenableexcept(FE_DIVBYZERO) error\n") ;
exit (1) ;
}
printf("after enabling FE_DIVBYZERO trap, we have :\n");
print_fe() ;
/* feholdexcept */
printf("saving environment\n");
if (feholdexcept(&holdenv) != 0) {
fprintf (stderr, "feholdexcept error\n");
exit (1) ;
}
printf("after saving environment, we have :\n");
print_fe() ;
return 0;
}
Do you think this is a bug ?
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- feholdexcept() does not seem to clear the exception flags correctly,
Bernard WEISSER <=