Mail Archives: djgpp/1997/08/28/00:31:06
On 25 Aug 1997, Jos Bergervoet wrote:
> There is actually no need to prevent division by zero. It should
> produce Inf or Nan, and often your computation can go on and
> still deliver good results. DJGPP doesn't fail on this:
>
> double a=1, b=0, c;
> c = a/b; /* now c=Inf */
> c = 1/c; /* now c=1/Inf = 0, which is correct */
> printf( "Hello: result = %10.4g\n", c );
On an INTEL PC a divide by zero will cause a hardware exception that will
cause the processor to halt. It will return Inf or NaN only if you
install an exception handler that returns that value when the processor
flags the exception.
On some other machines (namely the SGI that I work on) the processor will
return an Inf or NaN by itself, but the state of the processor is such
that it will produce a steady stream of garbage afterwards. Personally
I prefer a simple exception, thank you very much.
---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto
- Raw text -