Hi,

Is there a reason why in fpc both floating point and integer division
by zero raise an EDivByZero exception?

See: http://docwiki.embarcadero.com/VCL/en/SysUtils.EZeroDivide

SysUtils.EZeroDivide exception is raised when an application attempts
to divide a floating-point value by zero.
Note:  Integer divide-by-zero errors raise the SysUtils.EDivByZero exception.

program zerodiv;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}

uses Sysutils;

var r,x: extended;
    i,j: integer;

begin
  i := 0;
  r := 0.0;
  try
    write('Integer division by zero: 1 div 0   -> ');
    j := 1 div i;
    writeln(j);
  except
    on e: exception do writeln(e.classname);
  end;
  try
    write('Float division by zero  : 1.0 / 0.0 -> ');
    x := 1.0 / r;
    writeln(x);
  except
    on e: exception do writeln(e.classname);
  end;
end.

Output with Delphi (3.0:
Integer division by zero: 1 div 0   -> EDivByZero
Float division by zero  : 1.0 / 0.0 -> EZeroDivide

Output with Fpc 2.2.4 (tested on win32 and Linux i386)
Integer division by zero: 1 div 0   -> EDivByZero
Float division by zero  : 1.0 / 0.0 -> EDivByZero

Is this by design, or should I report it as a bug?
(B.t.w. setting mode to delphi makes no difference)

Bart
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to