Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!hsdndev!cmcl2!cmcl2 From: mcqueen@acf4.NYU.EDU (David M. McQueen) Newsgroups: comp.lang.fortran Subject: Re: detecting Nan's Message-ID: <9101111859.AA27169@acf4.NYU.EDU> Date: 11 Jan 91 18:59:59 GMT Lines: 54 From mcqueen@acf4.NYU.EDU Fri Jan 11 14:00:26 1991 Received: from ACF4.NYU.EDU by cmcl2.NYU.EDU (5.61/1.34) id AA22195; Fri, 11 Jan 91 14:00:26 -0500 Received: by acf4.NYU.EDU (5.61/1.34) id AA27169; Fri, 11 Jan 91 13:59:59 -0500 Date: Fri, 11 Jan 91 13:59:59 -0500 From: mcqueen@acf4.NYU.EDU (David M. McQueen) Message-Id: <9101111859.AA27169@acf4.NYU.EDU> To: rnews@cmcl2.NYU.EDU Relay-Version: version nyu B notes v1.6.1 1/11/90; site acf4.NYU.EDU From: mcqueen@acf4.NYU.EDU (David M. McQueen) Date: 11 Jan 91 13:59 EST Date-Received: 11 Jan 91 13:59 EST Subject: Re: detecting Nan's Message-ID: <13160008@acf4.NYU.EDU> Path: acf4!mcqueen Newsgroups: comp.lang.fortran Posting-Version: version nyu B notes v1.6.1 1/11/90; site acf4.NYU.EDU Organization: New York University References: <9101110259.AA28451@ucbvax.Berkeley.EDU> 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.