Fixed Div0-Error
This commit is contained in:
@@ -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;
|
||||
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
|
||||
begin
|
||||
var valB: Int64 := B;
|
||||
if valB = 0 then
|
||||
raise EDivByZero.Create('Division by zero');
|
||||
Result := A.Value.AsDouble / valB;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user