[fpc-pascal] Division by Zero: EDivByZero and EZeroDivide

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Oct 19 14:49:34 CEST 2009


On 19 Oct 2009, at 14:36, Jonas Maebe wrote:

> In case it's Mac OS X on x86: floating point exception reporting via  
> Unix signals isn't exactly its forte.

And in case Mac OS X on ppc: the same caveats apply as for x86, except  
that we don't have to any opcode decoding since the PPC doesn't raise  
a hardware exception for integer div-by-zero. The system does appear  
to raise the wrong exception for your test program though, but there's  
not much we can do about that. This is basically our signal handler:

   case sig of
     SIGFPE :
       begin
         Case Info^.si_code Of
           FPE_FLTDIV,
           FPE_INTDIV : Res:=200;  { floating point divide by zero }
           FPE_FLTOVF : Res:=205;  { floating point overflow }
           FPE_FLTUND : Res:=206;  { floating point underflow }
           FPE_FLTRES,             { floating point inexact result }
           FPE_FLTINV : Res:=207;  { invalid floating point operation }
           Else
             Res:=207; {coprocessor error}
         end;

If the system say its FPE_FLTDIV (which according to /usr/include/sys/ 
signal.h means "[XSI] floating point divide by zero"), we report that...


Jonas



More information about the fpc-pascal mailing list