TAChart: Add InRangeUlps utility function

git-svn-id: trunk@38232 -
This commit is contained in:
ask 2012-08-13 11:45:55 +00:00
parent 9429d4dcd4
commit 09924a0960

View File

@ -31,6 +31,8 @@ procedure EnsureOrder(var A, B: Double); overload; inline;
procedure ExpandRange(var ALo, AHi: Double; ACoeff: Double);
function InRangeUlps(AX, ALo, AHi: Double; AMaxUlps: Word): Boolean;
function SafeInfinity: Double; inline;
function SafeInRange(AValue, ABound1, ABound2: Double): Boolean;
function SafeMin(A, B: Double): Double;
@ -41,6 +43,8 @@ implementation
uses
Math, spe, TAChartUtils;
function Ulps(AX: Double): Int64; forward;
// Cumulative normal distribution
// x = -INF ... INF --> Result = 0 ... 1
function CumulNormDistr(AX: Double): Double;
@ -143,6 +147,11 @@ begin
AHi += d * ACoeff;
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;
begin
{$PUSH}{$R-}{$Q-}
@ -175,5 +184,14 @@ begin
{$POP}
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.