From 4b2fe1385316c47b4c48aad18d2c419ac5ccb227 Mon Sep 17 00:00:00 2001 From: ask Date: Mon, 24 Sep 2012 14:37:53 +0000 Subject: [PATCH] TAChart: Add IsEquivalent utility function git-svn-id: trunk@38811 - --- components/tachart/tachartutils.pas | 6 ++++++ components/tachart/test/UtilsTest.pas | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/components/tachart/tachartutils.pas b/components/tachart/tachartutils.pas index 17cc372c22..1dbb55275e 100644 --- a/components/tachart/tachartutils.pas +++ b/components/tachart/tachartutils.pas @@ -293,6 +293,7 @@ function FormatIfNotEmpty(AFormat, AStr: String): String; inline; function IfThen(ACond: Boolean; ATrue, AFalse: TObject): TObject; overload; function InterpolateRGB(AColor1, AColor2: Integer; ACoeff: Double): Integer; function IntToColorHex(AColor: Integer): String; inline; +function IsEquivalent(const A1, A2: Double): Boolean; inline; function IsNan(const APoint: TDoublePoint): Boolean; overload; inline; function NumberOr(ANum: Double; ADefault: Double = 0.0): Double; inline; @@ -424,6 +425,11 @@ begin Result := '$' + IntToHex(AColor, 6); end; +function IsEquivalent(const A1, A2: Double): Boolean; +begin + Result := CompareDWord(A1, A2, SizeOf(A1) div SizeOf(DWord)) = 0; +end; + function IsNan(const APoint: TDoublePoint): Boolean; begin Result := IsNan(APoint.X) or IsNan(APoint.Y); diff --git a/components/tachart/test/UtilsTest.pas b/components/tachart/test/UtilsTest.pas index 27bac26c2d..260e003434 100644 --- a/components/tachart/test/UtilsTest.pas +++ b/components/tachart/test/UtilsTest.pas @@ -40,6 +40,7 @@ type TMathTest = class(TTestCase) published procedure CumulNurmDistrTest; + procedure TestIsEquivalent; end; TGeometryTest = class(TTestCase) @@ -172,6 +173,16 @@ begin AssertEquals(p, InvCumulNormDistr(CumulNormDistr(p))); end; +procedure TMathTest.TestIsEquivalent; +begin + AssertTrue(IsEquivalent(1.2345, 1.2345)); + AssertTrue(IsEquivalent(SafeNaN, SafeNaN)); + AssertTrue(IsEquivalent(1e100, 1e100+1)); + AssertFalse(IsEquivalent(1e10, 1e10+1)); + AssertFalse(IsEquivalent(5, SafeNaN)); + AssertFalse(IsEquivalent(SafeNaN, 5)); +end; + { TGeometryTest } procedure TGeometryTest.AssertEquals(const Expected, Actual: TDoublePoint);