Happens in GetExponent functions only if range checking is on.
Solution:
replace
Result := E - CDoubleBias
with
Result := Integer(E) - Integer(CDoubleBias)
in FloatUtils.pas
function GetExponent(const AValue: Single): Integer; overload;
var
M, E: UInt32;
begin
M := GetRawSignificand(AValue);
E := GetRawExponent(AValue);
if (0 < E) and (E < CSingleExponentMask) then
Result := Integer(E) - Integer(CSingleBias)
else if E = 0 then
if M = 0 then
// +/- Zero
Result := 0
else
// Denormal
Result := 1 - CSingleBias
else
// NaN or +/-Infinity
Result := 0;
end;
function GetExponent(const AValue: Double): Integer; overload;
var
M: UInt64;
E: UInt32;
begin
M := GetRawSignificand(AValue);
E := GetRawExponent(AValue);
if (0 < E) and (E < CDoubleExponentMask) then
Result := Integer(E) - Integer(CDoubleBias)
else if E = 0 then
if M = 0 then
// +/-Zero
Result := 0
else
// Denormal
Result := 1 - CDoubleBias
else
// NaN or +/-Infinity
Result := 0;
end;
function GetExponent(const AValue: Extended): Integer; overload;
var
M: UInt64;
E: UInt32;
begin
M := PUInt64(@AValue)^;
E := GetRawExponent(AValue);
if (0 < E) and (E < CExtendedExponentMask) then
Result := Integer(E) - Integer(CExtendedBias)
else if E = 0 then
if M = 0 then
// +/- Zero
Result := 0
else
// Denormal
Result := 1 - CExtendedBias
else
// NaN or +/-Infinity
Result := 0;
end;
Happens in GetExponent functions only if range checking is on.
Solution: replace Result := E - CDoubleBias with Result := Integer(E) - Integer(CDoubleBias) in FloatUtils.pas
function GetExponent(const AValue: Single): Integer; overload; var M, E: UInt32; begin M := GetRawSignificand(AValue); E := GetRawExponent(AValue); if (0 < E) and (E < CSingleExponentMask) then Result := Integer(E) - Integer(CSingleBias) else if E = 0 then if M = 0 then // +/- Zero Result := 0 else // Denormal Result := 1 - CSingleBias else // NaN or +/-Infinity Result := 0; end;
function GetExponent(const AValue: Double): Integer; overload; var M: UInt64; E: UInt32; begin M := GetRawSignificand(AValue); E := GetRawExponent(AValue); if (0 < E) and (E < CDoubleExponentMask) then Result := Integer(E) - Integer(CDoubleBias) else if E = 0 then if M = 0 then // +/-Zero Result := 0 else // Denormal Result := 1 - CDoubleBias else // NaN or +/-Infinity Result := 0; end;
function GetExponent(const AValue: Extended): Integer; overload; var M: UInt64; E: UInt32; begin M := PUInt64(@AValue)^; E := GetRawExponent(AValue); if (0 < E) and (E < CExtendedExponentMask) then Result := Integer(E) - Integer(CExtendedBias) else if E = 0 then if M = 0 then // +/- Zero Result := 0 else // Denormal Result := 1 - CExtendedBias else // NaN or +/-Infinity Result := 0; end;