Xref: utzoo comp.unix.ultrix:7507 comp.lang.fortran:5612 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!ucsd!rutgers!modus!otello!gear!cadlab!martelli From: martelli@cadlab.sublink.ORG (Alex Martelli) Newsgroups: comp.unix.ultrix,comp.lang.fortran Subject: Re: How to detect NaN's Message-ID: <889@cadlab.sublink.ORG> Date: 4 Jun 91 08:00:49 GMT References: <1991May30.204332.16506@litwin.com> Organization: CAD.LAB, Bologna, Italia Lines: 52 warren@atmos.washington.edu (David Warren) writes: :In article <1991May30.204332.16506@litwin.com> vlr@litwin.com (Vic Rice) writes: ... : I have encountered a problem on a DECStation 5000 using the Mips Fortran ... :how about linking with this c function: : :int *check_nan_(num) :/*make sure num != NaN*/ :float *num; :{ : int true=1,false=0; : if(isnan((double)num))return(&true); : else return(&false); :} : :then do : :ISTAT = CHECK_NAN(RVAL) There are several problems here! Integer and Logical function results are to be returned by-value, not by-reference, on DECstations as well as all other platforms I know; Fortran .TRUE. is generally -1, not 1; it is dangerous for a C function to return the address of a variable of 'automatic' storage class, since the storage it is pointing to is "going away" (i.e. about to be recycled for automatic variables of further called functions) just after the execution of the return statement; it is wrong to cast num, which is the ADDRESS of a float, to a double - what you want to do is cast the POINTED-TO value, *num, and such a cast is not needed anyway since floats are promoted to double by default in C when used in expressions. All in all, the idea is not bad, but the implementation should preferably be something like: int checknan(num) float *num; { return isnan(*num) ? -1 : 0 ; } to be declared and used like this: LOGICAL CHECKNAN ... IF(CHECKNAN(RVAL)) THEN WRITE(*,*) 'HELP! RVAL is Not A Number!' ELSE WRITE(*,*) 'All is fine so far...' ENDIF -- Alex Martelli - CAD.LAB s.p.a., v. Stalingrado 53, Bologna, Italia Email: (work:) martelli@cadlab.sublink.org, (home:) alex@am.sublink.org Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; Fax: ++39 (51) 366964 (work only), Fidonet: 332/407.314 (home only).