|
From: <san...@gm...> - 2009-03-08 18:51:12
|
Hi,
I have just started using Valgrind, it's a fantastic tool!
Among other things, I am concerned about potential floating
exceptions, so I set an adequate mask. The point is that most of the
operations that raise a FPE when executing normally, do not raise it
when executing through Valgrind. I found no info about it, so I do not
know if that is the intended behaviour (which I guess is not very
desirable). When using Valgrind, NaNs, infs, underflows, etc., wander
around like happy beasts.
I am including below the code that I used to test this. It's a
particular case of an underflow, not trapped by Valgrind. It's like it
does not let my code set the mask. I had a bunch of other FPEs that
went through with VG. Actually, the only one that I could trap is
floating exception: Numerical argument out of domain
FPE_INTDIV (integer divide by zero floating exception)
(these were reported via an strerror and a siginfo_t).
My system:
Linux 2.6.18-8.el5 #1 SMP x86_64
gcc (GCC) 4.1.1
Thanks!
---------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#define _GNU_SOURCE 1
#define __USE_GNU 1
#include <fenv.h>
#include <math.h>
void trap_fpe(void)
{
//The function returns the previous enabled exceptions in case the
operation was successful, -1 otherwise.
feenableexcept(FE_UNDERFLOW
//FE_INVALID
//| FE_DIVBYZERO
//| FE_OVERFLOW
//|
//| FE_INEXACT
);
return;
}
void gen_underflow(void);
int main( void )
{
printf("Setting the FPU\n");
trap_fpe(); /* If not active, get the core dump */
gen_underflow();
return 0;
}
void gen_underflow(void)
{
double d = 0.5;
int i = 0;
printf("Generating underflow\n");
while ( i < 20 ) {
//while ( 1 ) {
i++;
/*d /= 2.0;
printf("computing 2^(-%d) = %le\n", i + 1, d);*/
d *= d;
printf("computing 2^(-2^%d) = %le\n", i, d);
}
printf("\n");
}
|