mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 04:29:17 +02:00
+ added Inf/Nan stuff
This commit is contained in:
parent
df4665129f
commit
b43854bb09
@ -114,6 +114,10 @@ interface
|
||||
EqualsValue = 0;
|
||||
LessThanValue = Low(TValueRelationship);
|
||||
GreaterThanValue = High(TValueRelationship);
|
||||
{$ifndef ver1_0}
|
||||
NaN = 0.0/0.0;
|
||||
Infinity = 1.0/0.0;
|
||||
{$endif ver1_0}
|
||||
|
||||
{ Min/max determination }
|
||||
function MinIntValue(const Data: array of Integer): Integer;
|
||||
@ -151,10 +155,6 @@ function EnsureRange(const AValue, AMin, AMax: Int64): Int64;
|
||||
function EnsureRange(const AValue, AMin, AMax: Double): Double;
|
||||
{$endif FPC_HAS_TYPE_DOUBLE}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Sign functions
|
||||
Type
|
||||
TValueSign = -1..1;
|
||||
@ -179,6 +179,9 @@ function IsZero(const A: Extended; Epsilon: Extended): Boolean;
|
||||
function IsZero(const A: Extended): Boolean;
|
||||
{$endif FPC_HAS_TYPE_EXTENDED}
|
||||
|
||||
function IsNan(const d : Double): Boolean;
|
||||
function IsInfinite(const d : Double): Boolean;
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||
function SameValue(const A, B: Extended): Boolean;
|
||||
{$endif}
|
||||
@ -1206,6 +1209,46 @@ begin
|
||||
end;
|
||||
{$endif FPC_HAS_TYPE_EXTENDED}
|
||||
|
||||
|
||||
type
|
||||
TSplitDouble = packed record
|
||||
cards: Array[0..1] of cardinal;
|
||||
end;
|
||||
|
||||
function IsNan(const d : Double): Boolean;
|
||||
var
|
||||
fraczero, expMaximal: boolean;
|
||||
begin
|
||||
{$if defined(BIG_ENDIAN) or (defined(CPUARM) and defined(FPUFPA))}
|
||||
expMaximal := ((TSplitDouble(d).cards[0] shr 20) and $7ff) = 2047;
|
||||
fraczero:= (TSplitDouble(d).cards[0] and $fffff = 0) and
|
||||
(TSplitDouble(d).cards[1] = 0);
|
||||
{$else BIG_ENDIAN}
|
||||
expMaximal := ((TSplitDouble(d).cards[1] shr 20) and $7ff) = 2047;
|
||||
fraczero := (TSplitDouble(d).cards[1] and $fffff = 0) and
|
||||
(TSplitDouble(d).cards[0] = 0);
|
||||
{$endif BIG_ENDIAN}
|
||||
Result:=expMaximal and not(fraczero);
|
||||
end;
|
||||
|
||||
|
||||
function IsInfinite(const d : Double): Boolean;
|
||||
var
|
||||
fraczero, expMaximal: boolean;
|
||||
begin
|
||||
{$if defined(BIG_ENDIAN) or (defined(CPUARM) and defined(FPUFPA))}
|
||||
expMaximal := ((TSplitDouble(d).cards[0] shr 20) and $7ff) = 2047;
|
||||
fraczero:= (TSplitDouble(d).cards[0] and $fffff = 0) and
|
||||
(TSplitDouble(d).cards[1] = 0);
|
||||
{$else BIG_ENDIAN}
|
||||
expMaximal := ((TSplitDouble(d).cards[1] shr 20) and $7ff) = 2047;
|
||||
fraczero := (TSplitDouble(d).cards[1] and $fffff = 0) and
|
||||
(TSplitDouble(d).cards[0] = 0);
|
||||
{$endif BIG_ENDIAN}
|
||||
Result:=expMaximal and fraczero;
|
||||
end;
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||
function SameValue(const A, B: Extended; Epsilon: Extended): Boolean;
|
||||
|
||||
@ -1266,7 +1309,10 @@ end;
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.19 2004-02-09 18:53:09 florian
|
||||
Revision 1.20 2004-02-20 20:10:44 florian
|
||||
+ added Inf/Nan stuff
|
||||
|
||||
Revision 1.19 2004/02/09 18:53:09 florian
|
||||
* compilation on ppc fixed
|
||||
|
||||
Revision 1.18 2004/02/09 17:21:04 marco
|
||||
|
Loading…
Reference in New Issue
Block a user