Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!teknowledge-vaxc!sri-unix!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.fortran Subject: Re: Fortran vs C for computations Message-ID: <356@quintus.UUCP> Date: 6 Sep 88 08:35:48 GMT References: <535@nikhefh.hep.nl> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 23 In article <535@nikhefh.hep.nl> t68@nikhefh.hep.nl (Jos Vermaseren) writes: > >In the second edition of Kernighan and Ritchie it is explained that the >standard response of a floating point operation (multiplication, sqrt etc) >to an irregularity is returning special values. > >So > float x = -2.0; > z = sqrt(x); > >gives back some value. Amazingly enough many UNIX vendors like this philosophy, >so even the UNIX fortran compilers often prefer it this way. (1) See "matherr" in the System V documentation. If you define a function int matherr(struct exception *x) it will be called when math library functions detect a problem. (2) Returning funny values is exactly what IEEE floating point arithmetic is all about. Note that the IEEE 754 standard requires AS THE DEFAULT that x+z and the like should return infinities or NaNs in various circumstances, rather than signalling an exception, and that IEEE 754 provides no standard way of enabling exceptions (though it suggests that there should be one).