Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

checking where sqrt(-1) occurs

25 views
Skip to first unread message

Bart Vandewoestyne

unread,
May 6, 2009, 5:42:30 AM5/6/09
to
Using gfortran or g95, is it possible to check at runtime where
an sqrt(-1) is being calculated?

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."

Ian Bush

unread,
May 6, 2009, 5:52:13 AM5/6/09
to
On 6 May, 10:42, Bart Vandewoestyne

<MyFirstName.MyLastN...@telenet.be> wrote:
> Using gfortran or g95, is it possible to check at runtime where
> an sqrt(-1) is being calculated?
>

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

Bart Vandewoestyne

unread,
May 6, 2009, 6:07:29 AM5/6/09
to
On 2009-05-06, Ian Bush <ianbush.thro...@googlemail.com> wrote:
>
> 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,

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,

Ian Bush

unread,
May 6, 2009, 6:14:26 AM5/6/09
to
On 6 May, 11:07, Bart Vandewoestyne
<MyFirstName.MyLastN...@telenet.be> wrote:

> On 2009-05-06, Ian Bush <ianbush.throwaway.acco...@googlemail.com> wrote:
>
>
>
> > 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,
>
> 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.
>

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

Ian Bush

unread,
May 6, 2009, 6:16:46 AM5/6/09
to
On 6 May, 11:07, Bart Vandewoestyne
<MyFirstName.MyLastN...@telenet.be> wrote:
> On 2009-05-06, Ian Bush <ianbush.throwaway.acco...@googlemail.com> wrote:
>
>
>
> > 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,
>
> 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.
>

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

me...@skyway.usask.ca

unread,
May 6, 2009, 3:27:58 AM5/6/09
to

Brute force solution - but portable!!!! (which seems to be of
prime inportance in this NG)
Just check each arg before its square root.

Chris

Dave Allured

unread,
May 6, 2009, 12:29:20 PM5/6/09
to

Thanks Ian! I need to work these settings into my standard build and
run setups!

--Dave

Bart Vandewoestyne

unread,
May 7, 2009, 9:53:22 AM5/7/09
to
On 2009-05-06, Ian Bush <ianbush.thro...@googlemail.com> wrote:
>
> 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]

Thanks! This is exactly what we were looking for!

0 new messages