mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-25 00:29:25 +02:00
* handle frac(+/-Inf or Nan) correctly in the software implementation, resolves #39584
This commit is contained in:
parent
b3e079c5da
commit
67fedc6b5b
@ -1757,10 +1757,17 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
{$ifndef FPC_SYSTEM_HAS_FRAC}
|
{$ifndef FPC_SYSTEM_HAS_FRAC}
|
||||||
function fpc_frac_real(d : ValReal) : ValReal;compilerproc;
|
function fpc_frac_real(d : ValReal) : ValReal;compilerproc;
|
||||||
begin
|
var
|
||||||
result := d - Int(d);
|
i: integer;
|
||||||
end;
|
begin
|
||||||
|
i := (float64high(d) and $7ff00000) shr 20;
|
||||||
|
if i=$7FF then
|
||||||
|
{ return NaN }
|
||||||
|
result := (d-d)/0.0
|
||||||
|
else
|
||||||
|
result := d - Int(d);
|
||||||
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
|
|
||||||
|
24
tests/test/units/system/tfrac.pp
Normal file
24
tests/test/units/system/tfrac.pp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{ %OPT=-O- }
|
||||||
|
uses
|
||||||
|
math,sysutils;
|
||||||
|
var
|
||||||
|
d : double;
|
||||||
|
s : string;
|
||||||
|
begin
|
||||||
|
SetExceptionMask([exInvalidOp]);
|
||||||
|
d:=Infinity;
|
||||||
|
str(frac(d),s);
|
||||||
|
writeln(s);
|
||||||
|
if pos('Nan',s)=0 then
|
||||||
|
halt(1);
|
||||||
|
d:=-Infinity;
|
||||||
|
str(frac(d),s);
|
||||||
|
writeln(s);
|
||||||
|
if pos('Nan',s)=0 then
|
||||||
|
halt(1);
|
||||||
|
d:=NaN;
|
||||||
|
str(frac(d),s);
|
||||||
|
writeln(s);
|
||||||
|
if pos('Nan',s)=0 then
|
||||||
|
halt(1);
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user