[net.lang.f77] fixes available to 4.2BSD libF77 to comply with the ANSI standard

paul@oddjob.UChicago.UUCP (Paul Schinder) (12/22/84)

<>
If anyone is interested in changes to the 4.2 fortran library and to
/usr/lib/f77pass1 to make intrinsic functions do the proper thing (give an
error message and dump core) when passed illegal arguments, please send me
mail (after December 30, I will be gone until then).  If there is an
overwhelming response, I will post them to net.sources.

As an example, if you say

	x = sqrt(-1.)

with the current library, you will find that x = 0.  You will not be warned
that sqrt was called with an illegal value.  The fixed library would
say

	sqrt: called with argument -1.

and dump a core so you could tell where the error occured.  I have changed
sqrt, log, asin, acos, and mod to conform to the standards written out on
pages 15-28 and 15-29 of the ANSI Fortran 77 document.  I have also changed
exp to check for overflows and underflows; you may or may not want this.

These changes are very simple.  I didn't try to do anything fancy.  We have
been bothered for a long time with bogus values being silently returned from
fortran intrinsic functions when they were given illegal values of the
arguments.  Now that we have several different types of machines around, the
added portability that conforming to the standard gives us is very
important.  Besides, hidden bugs may lurk in your programs that you will
never know about otherwise.  I have found three since I made the changes.
And normal users of fortran on this machine would probably never find out
that the intrinsic functions behave this way, because, so far as I know, the
behavior of sqrt, log, etc., when given illegal arguments is only spelled
out in the manual page for the C math library.  A normal fortran user here
would probably never find out that these were the routines actually being
called by the fortran intrisic functions.

If someone out there is really brave, they could fix libm.  I didn't do that
because for all I know, something in 4.2 *depends* on this behavior from
the math routines.
-- 


				Paul Schinder
				Astronomy and Astrophysics Center
				University of Chicago
				uucp: ..!ihnp4!oddjob!paul

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (12/26/84)

> 	x = sqrt(-1.)

sqrt: DOMAIN error

> If someone out there is really brave, they could fix libm.

Talk about reinventing the wheel!  Instead of pouring so much effort
into obsolete versions of software, why not start with the latest
available version (UNIX System V Release 2.0) and improve that?  Then
you could also feed back your improvements to AT&T so everyone could
benefit.

The "sqrt: DOMAIN error" message is what you get by default under
UNIX System V.  You can also supply your own matherr() routine to
allow special handling of math library exceptions; much better than
core dumping!