[comp.unix.questions] Division by Zero questions?

megabyte@chinet.UUCP (Dr. Megabyte) (11/14/86)

The following questions relate to the following short "C" program:

main()
{
        float x;
        float y;

        y = 0;
        x = 5/y;
        printf("%f \n",x);
}

On my AT&T 3b2/400 with SYS V R2.04, the program dumps core at the line with
the division and prints the message:"Floating Point Exception - Core dumped".
This seemed reasonable to me. The I tried the same program on my Zilog Model
31 running Zeus 3.21, which is a SYS III port and the program did NOT dump
core. When it got to the printf statement it printed "INF" Which I assume
must mean "Is Not Float". I can find no documentation on this, though if I 
change the floats above to ints, the Zilog prints "NAN" as the result.

Now, I feel the AT&T is doing the correct thing. The question is what in the
world is my Zilog doing, and where do those "NAN" and "INF" messages come from
on the printf statements.

Reply by e-mail or to the net as appropriate

The opinions expressed herein are my own and do not reflect those of 
the Internal Revenue Service or any other agency of the United States
Government. (A US Gov't disclaimer designed to protect the taxpayers 
from their fellow taxpayers)
-- 
UUCP:	(1) seismo!why_not!scsnet!sunder		Mark E. Sunderlin
	(2) ihnp4!chinet!megabyte			aka Dr. Megabyte
CIS:	74026,3235					(202) 634-2529
Mail:	IRS  PM:PFR:D:NO  1111 Constitution Ave. NW  Washington,DC 20224  

dlc@zog.cs.cmu.edu (Daryl Clevenger) (11/16/86)

As far as I know, some systems have special values for various conditions
that can result from floating point operations.  Those sytems that do not
have these values dump core, but on those that do, they set the value and
continue onward.  On your Zilog model, I suspect that "INF" is infinity and
is the value set when a floating point division by zero is attempted.  I
do not know what "NAN" means.  Also, I'm not sure what happens if you use
an "INF" value in a computation.  Also, I suspect that there are values to
indicate overflow and underflow.  I believe that much of this is specified
in the IEEE floating point standard, but not all hardware uses this
standard.

mac@esl.UUCP (Mike McNamara) (11/17/86)

In article <763@chinet.UUCP> megabyte@chinet.UUCP (Dr. Megabyte) writes:
>The following questions relate to the following short "C" program:
>
>main()
>{
>        float x;
>        float y;
>
>        y = 0;
>        x = 5/y;
>        printf("%f \n",x);
>}
>
>On my AT&T 3b2/400 with SYS V R2.04, the program dumps core at the line with
>the division and prints the message:"Floating Point Exception - Core dumped".
>This seemed reasonable to me. The I tried the same program on my Zilog Model
>31 running Zeus 3.21, which is a SYS III port and the program did NOT dump
>core. When it got to the printf statement it printed "INF" Which I assume

Given a constant K, 

	limit / K \
	x->0  |---|  = INFinity ;  Hence the Zilog machine printed INF.
	      \ x / 

>must mean "Is Not Float". I can find no documentation on this, though if I 
      INFinity
>change the floats above to ints, the Zilog prints "NAN" as the result.

      and NAN means Not A Number.  Why the difference?  All I can offer
      is that infinity means something in floating point, ( exponent is
      larger than machine precision) where as it really doesn't mean
      the same thing for fixed point.  (simple overflow).  
      You might disagree, but 2147483647 (=2**31-1) { the maximum
      integer on a vax} is much less than infinity, and is also much
      less than ~1.701412E38 (=~2**127) the maximum float on a vax,
      which your zilog is calling INF.

>
>Now, I feel the AT&T is doing the correct thing. The question is what in the
>world is my Zilog doing, and where do those "NAN" and "INF" messages come from
>on the printf statements.
	Protecting you from core dumps.  The Zilog math library, (or stdio
	library) understands what numbers are, and tries to rationally give
	you the results of your calculations.  The AT&T blindly does as you
	tell it.

scott@gitpyr.gatech.EDU (Scott Holt) (11/17/86)

>Now, I feel the AT&T is doing the correct thing. The question is what in the
>world is my Zilog doing, and where do those "NAN" and "INF" messages come from
>on the printf statements.
>

   I suspect that INF means INFinite (which is what some people call the 
result of devision by zero) and NAN means "Not A Number." 

   Some machines have a floating point representation for infinity and a
corresponding integer representation. Such machines may allow operations
that result in infinity and only give an error when infinity is used in
another calculation.  Since the machine has a representation for infinity,
the I/O routines need a way to print this value...hence INF/NAN.

                     - Scott Holt
                       scott@gitpyr