Path: utzoo!attcan!uunet!cs.utexas.edu!yale!venus!yalevm!maine!gandalf!acf4!mcqueen From: mcqueen@acf4.NYU.EDU (David M. McQueen) Newsgroups: comp.lang.fortran Subject: Re: detecting Nan's Message-ID: <13160008@acf4.NYU.EDU> Date: 11 Jan 91 18:59:00 GMT References: <9101110259.AA28451@ucbvax.Berkeley.EDU> Sender: news@gandalf.UMCS.Maine.EDU Organization: New York University Lines: 32 Recently, Frank Elliott, one of the mathematicians here at the Courant Institute, found himself in the position of trying to detect NaN in his C code on a Stellar GS2000. Although the man pages suggested that there were library functions for NaN-detection (e.g., "isnand") , in fact the installed library did not have these functions. Frank came up with a clever kludge which I have translated to (and used in) Fortran. We have taken to calling this "Elliott's Device". The Fortran translation below is not guaranteed to be portable, but I think it could be made portable with relatively little work. I would not recommend this for numerically intensive applications :-). character*80 test x = 0.0 y = 0.0 z = x/y write(6,*) z write(test,*) z c Elliott's Device write(6,'(a)') test if (test(1:4) .eq. ' NaN') write(6,*) 'z is NaN' end ------------------------------------------------------------------------------- PS: I tried to post this earlier and it may or may not have actually gotten out. I have received email (from Peter Shenkin; thank you, Peter) that the line: write(test,*) z is an illegal unformatted internal write. I have done this successfully on a Sun 3/50 running f77 under SunOS 4.1. No guarantees can be made about other systems.