mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-26 17:21:05 +02:00
TAChart: Add InRangeUlps utility function
git-svn-id: trunk@38232 -
This commit is contained in:
parent
9429d4dcd4
commit
09924a0960
@ -31,6 +31,8 @@ procedure EnsureOrder(var A, B: Double); overload; inline;
|
|||||||
|
|
||||||
procedure ExpandRange(var ALo, AHi: Double; ACoeff: Double);
|
procedure ExpandRange(var ALo, AHi: Double; ACoeff: Double);
|
||||||
|
|
||||||
|
function InRangeUlps(AX, ALo, AHi: Double; AMaxUlps: Word): Boolean;
|
||||||
|
|
||||||
function SafeInfinity: Double; inline;
|
function SafeInfinity: Double; inline;
|
||||||
function SafeInRange(AValue, ABound1, ABound2: Double): Boolean;
|
function SafeInRange(AValue, ABound1, ABound2: Double): Boolean;
|
||||||
function SafeMin(A, B: Double): Double;
|
function SafeMin(A, B: Double): Double;
|
||||||
@ -41,6 +43,8 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Math, spe, TAChartUtils;
|
Math, spe, TAChartUtils;
|
||||||
|
|
||||||
|
function Ulps(AX: Double): Int64; forward;
|
||||||
|
|
||||||
// Cumulative normal distribution
|
// Cumulative normal distribution
|
||||||
// x = -INF ... INF --> Result = 0 ... 1
|
// x = -INF ... INF --> Result = 0 ... 1
|
||||||
function CumulNormDistr(AX: Double): Double;
|
function CumulNormDistr(AX: Double): Double;
|
||||||
@ -143,6 +147,11 @@ begin
|
|||||||
AHi += d * ACoeff;
|
AHi += d * ACoeff;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function InRangeUlps(AX, ALo, AHi: Double; AMaxUlps: Word): Boolean;
|
||||||
|
begin
|
||||||
|
Result := InRange(Ulps(AX), Ulps(ALo) - AMaxUlps, Ulps(AHi) + AMaxUlps);
|
||||||
|
end;
|
||||||
|
|
||||||
function SafeInfinity: Double;
|
function SafeInfinity: Double;
|
||||||
begin
|
begin
|
||||||
{$PUSH}{$R-}{$Q-}
|
{$PUSH}{$R-}{$Q-}
|
||||||
@ -175,5 +184,14 @@ begin
|
|||||||
{$POP}
|
{$POP}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// Convert double value to integer 2's complement representation.
|
||||||
|
// Difference between resulting integers can be interpreted as distance in ulps.
|
||||||
|
function Ulps(AX: Double): Int64; inline;
|
||||||
|
begin
|
||||||
|
Result := Int64(AX);
|
||||||
|
if Result < 0 then
|
||||||
|
Result := (1 shl 63) - Result;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user