errno

Tom MacDonald uunet!fig.cray.com!tam
Fri Apr 5 11:07:17 PST 1991


> In what sense does awk or xcalc break?  If errno doesn't get set and
> awk prints NaN someplace, is that so bad?  I went down the hall and
> confirmed that Brian Kernighan, the owner of awk if anyone is, cares
> not one whit if errno goes away.

These are good questions and I'm happy to hear that Brian Kernighan
feels that way.  Also, I hope it did not come across that I was
besmirching `awk' or `xcalc' in any way.  I was just reporting on
the few instances of `errno' behavior with standard math functions
that I have come across.  In stark contrast to `errno' I find `awk'
to be very useful.

Since the CRI C implementation stops program execution and prints a
diagnostic to stdout whenever a domain or range error occurs, the situation
wasn't just a simple NaN appearing someplace.  Anyway, that is a
CRI issue that also affects our Fortran implementation.  In this case
the complaints did not come from customers, they came from CRI
employees trying to release a UNICOS system.

If I remember the `xcalc' code I saw, it compiled different code if
it was built on an implementation that supported IEEE arithmetic.
On an IEEE implementation `errno' was not used.  To me this only reinforces
my belief that `errno' gets in the way because the C standard requires
that it still must be set.

So - `awk' and `xcalc' break in the sense that a CRI employee opens
up a bug report against the C compiler when he believes the behavior
is incorrect.  Then, from the C compiler developer's point of view,
`awk' and `xcalc' break when `errno' behavior is not supported.

The second question does raise the whole issue of exception handling.
Printing a NaN someplace is not necessarily bad, but sometimes
programmers want their programs to stop executing when a square root
of a negative number is detected.  Waiting until the NaN prints
might not give enough information about where the NaN originated
from.  I suppose a similar argument can be made for divide by
zero producing infinities.

I admit that I've never been a big fan of NaNs.  From a compiler
writer's point of view they are analogous to tanks leveling our
neighborhoods because they eliminate the very optimizations we live
for.  We propagate constants, eliminate common subexpressions,
forward substitute values, and hoist invariants in hopes of detecting
a "X*0" or "X-X" so that it can be reduced to zero.  Signed zeros
do similar things to us poor oppressed compiler writers.

		"I'm not a number
		 I'm not a number
		 I'm not a number
		 Damit I'm a man"
				- Bob Seger and the Silver Bullet Band

hoping-no-one-takes-me-too-seriously yours,
denormal Tom



More information about the Numeric-interest mailing list