This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

Re: check if is NaN


(Cc: to gcc-bugs@gcc.gnu.org)
In article <8mr7bo$bf1$1@nnrp1.deja.com>,  <ezio_riva@my-deja.com> wrote:

>a) I 'm using g77 but I need to use the option -ffast-math.

I was quite surprised that

      external isnand
      logical isnand
      double precision a
      a = acos(1.2)
      print *,a,isnand(a)
      end
      logical function isnand(a)   
      double precision a
      isnand = a .ne. a
      end

produced

  NAN F

with GNU Fortran 0.5.25 19991030 (prerelease) on Linux i386 and
compilation with -O4 -ffast-math.  Inspection of the generated assembly
code showed

.globl isnand_
	.type	 isnand_,@function
isnand_:
	pushl %ebp
	movl %esp,%ebp
	xorl %eax,%eax
	leave
	ret

which shows that the test was optimized away.

I'm not sure wether to classify this as a bug or not.  The documentation
warns that -ffast-math makes programs non IEEE-conforming, but still...
What I would really like, I suppose, would be an ISNAN intrinsic
function.

BTW,

      isnand = a.ge. 0. .or. a .ne. 0.

works, but a very clever optimizer could also optimize this away...

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