A collegue of mine would like to know where in his program he's
computing an (erroneous) sqrt(-1). So he would like to know the line-number
where the sqrt(-1) occurs.
We're using:
bartv@gauss:~$ gfortran --version | head -1
GNU Fortran (Debian 4.3.2-1.1) 4.3.2
and
bartv@gauss:~$ g95 --version | head -1
G95 (GCC 4.1.2 (g95 0.92!) Mar 13 2009)
Thanks,
Bart
--
"Share what you know. Learn what you don't."
You could look into using one of the G95_FPU_* environment variables
to force the raising of a floating point exception. G95_FPU_INVALID
may be what you want, but I haven't looked into this too much,
Ian
Seems like gfortran has something similar, the -ffpe-trap=invalid
option. This raises a floating point exception when i have an
sqrt(-1.0), but unfortunately, one doesn't see the line number
where the sqrt(-1.0) occurs... and that's what we're looking
for...
If anybody knows how to do this, feel free to share.
Regards,
Wot now ? cat t.f90
Program test
Implicit None
Real :: a
Read( *, * ) a
Write( *, * ) Sqrt( a )
End Program test
Wot now ? gfortran -g -fbacktrace -ffpe-trap=invalid t.f90
Wot now ? ./a.out
-1.0
Program received signal 8 (SIGFPE): Floating-point exception.
Backtrace for this error:
+ [0x111400]
+ function test (0x8048709)
at line 9 of file t.f90
+ /lib/libc.so.6(__libc_start_main+0xe6) [0x65f5d6]
Ian
and for completeness
Wot now ? cat t.f90
Program test
Implicit None
Real :: a
Read( *, * ) a
Write( *, * ) Sqrt( a )
End Program test
Wot now ? export G95_FPU_INVALID=TRUE
Wot now ? export G95_SHOW_LOCUS=TRUE
Wot now ? g95 -g t.f90
Wot now ? ./a.out
-1.0
Floating point exception: Invalid operation
At line 9 of file t.f90 (Unit 6)
Traceback: not available, compile with -ftrace=frame or -ftrace=full
Ian
Brute force solution - but portable!!!! (which seems to be of
prime inportance in this NG)
Just check each arg before its square root.
Chris
Thanks Ian! I need to work these settings into my standard build and
run setups!
--Dave
Thanks! This is exactly what we were looking for!