[fpc-devel] function IsInt64(Double): Boolean;
J. Gareth Moreton
gareth at moreton-family.com
Mon May 4 23:19:47 CEST 2026
Oh, minor error, the $43F constant is meant to be $43E.
Kit
On 04/05/2026 22:18, J. Gareth Moreton via fpc-devel wrote:
> The quickest way, I think, is to look at the exponent bits of the
> Double. Though it returns a false negative for -(2^63):
>
> function OXmlIsInt64(const aNumber: Double): Boolean;
> var
> ExpMask: LongWord;
> DoubleBits: LongWord absolute aNumber;
> begin
> ExpMask := (DoubleBits shr 52) and $7FF;
> Result := (ExpMask >= $3FF) and (ExpMask < $43F);
> end;
>
> I think that's correct - I haven't actually tested it though. Note it
> only works for the standard IEEE 754 Double.
>
> Kit
>
> On 04/05/2026 21:48, Martin Frb via fpc-devel wrote:
>> On 04/05/2026 22:34, Ondrej Pokorny via fpc-devel wrote:
>>>
>>> I tried to switch overflow checks off:
>>> {$OVERFLOWCHECKS OFF}
>>>
>>> But obviously it doesn't help (it's a different exception).
>>
>> AFAIK:
>> You need to use SetExceptionMask, I think the below example should do:
>>
>>
>> procedure DisableFloatExceptions;
>> begin
>> if FloatExceptionLock = 0 then begin
>> EM := GetExceptionMask;
>> SetExceptionMask(EM + [exInvalidOp, exDenormalized, exZeroDivide,
>> exOverflow, exUnderflow, exPrecision]);
>> end;
>> inc(FloatExceptionLock);
>> end;
>>
>> procedure EnableFloatExceptions;
>> begin
>> dec(FloatExceptionLock);
>> if FloatExceptionLock <= 0 then begin
>> FloatExceptionLock := 0;
>> ClearExceptions(False);
>> SetExceptionMask(EM);
>> end;
>>
>> end;
>>
>>
>> _______________________________________________
>> fpc-devel maillist - fpc-devel at lists.freepascal.org
>> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>>
>
--
This email has been checked for viruses by Avast antivirus software.
www.avast.com
More information about the fpc-devel
mailing list