Fixed Div0-Error

This commit is contained in:
Michael Schimmel
2026-01-13 23:15:18 +01:00
parent 758e4eaa0e
commit 1258f79347
+19 -10
View File
@@ -620,17 +620,26 @@ begin
if (A.Kind in [TKind.DateTime, TKind.Keyword, TKind.Boolean]) or (B.Kind in [TKind.DateTime, TKind.Keyword, TKind.Boolean]) then
raise EArgumentException.CreateFmt('Operator Divide not supported for types %s and %s', [A.Kind.ToString, B.Kind.ToString]);
if B.Kind in [TKind.Float, TKind.DateTime] then
begin
Result := A.Value.AsDouble / B.Value.AsDouble;
end
else
begin
var valB: Int64 := B;
if valB = 0 then
raise EDivByZero.Create('Division by zero');
Result := A.Value.AsDouble / valB;
var res: Double := NaN;
case B.Kind of
TScalar.TKind.Ordinal:
if B.Value.AsInt64 <> 0 then
case A.Kind of
TScalar.TKind.Ordinal: res := A.Value.AsInt64 / B.Value.AsInt64;
TScalar.TKind.Float: res := A.Value.AsDouble / B.Value.AsInt64;
end
else
raise EDivByZero.Create('Division by zero');
TScalar.TKind.Float:
if B.Value.AsDouble <> 0.0 then
case A.Kind of
TScalar.TKind.Ordinal: res := A.Value.AsInt64 / B.Value.AsDouble;
TScalar.TKind.Float: res := A.Value.AsDouble / B.Value.AsDouble;
end;
end;
exit(res);
end;
class operator TScalar.IntDivide(const A, B: TScalar): TScalar;