Division by Zero questions?

Mike McNamara mac at esl.UUCP
Mon Nov 17 08:23:22 AEST 1986


In article <763 at chinet.UUCP> megabyte at 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.



More information about the Comp.unix.questions mailing list