This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

raising FE_INEXACT flag using constants in arithmetic operations (division)

Hi all,

I'm getting confused with the following source code and couldn't explain why the exception (here FE_INEXACT) is not raised.
the float stored in variable f is not exactly a floating point number and hence shall be round (to nearest as default behaviour).

Thanks in advance for your comments/help.

Best regards,

<<<<<<<<<< source >>>>>>>>>>>>>
#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>
#include <math.h>

int main (void)
        double f;
        int raised;

        feclearexcept (FE_ALL_EXCEPT);
        f = (double)((double)1.0/(double)3.0);

        raised = fetestexcept (FE_INEXACT);
        if (raised) printf("FE_TONEAREST : %a\n", f);
        return 0;
<<<<<<<<<< end >>>>>>>>>>>>>

Some machine related informations:

$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Core(TM)2 CPU         U7500  @ 1.06GHz
stepping        : 2
cpu MHz         : 1064.063
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm

$ uname -a
Linux xxxx 2.6.22-3-686 #1 SMP Mon Nov 12 08:32:57 UTC 2007 i686 GNU/Linux

$ gcc --v          
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

linking with :


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]