Table of Contents

Method AreCloseWithTolerance

Namespace
Alternet.UI
Assembly
Alternet.UI.Common.dll

AreCloseWithTolerance(double, double)

Determines whether two double-precision floating-point numbers are approximately equal within a specified relative and absolute tolerance.

public static bool AreCloseWithTolerance(double a, double b)

Parameters

a double

The first double-precision floating-point number to compare.

b double

The second double-precision floating-point number to compare.

Returns

bool

true if the two numbers are approximately equal within the defined tolerances; otherwise, false.

Remarks

The comparison uses a relative tolerance of 1e-12 and an absolute tolerance of 1e-15. This ensures that the method accounts for both small differences in large numbers and significant differences in numbers close to zero.

See Also

AreCloseWithTolerance(float, float)

Returns true if the two single-precision floats are close enough to be considered equal, using both relative and absolute tolerance.

public static bool AreCloseWithTolerance(float a, float b)

Parameters

a float

First value to compare.

b float

Second value to compare.

Returns

bool

true if the values are close; otherwise, false.

Examples

AreCloseWithTolerance(1.0f, 1.000001f);     // true
AreCloseWithTolerance(0.0f, 1e-8f);         // false
AreCloseWithTolerance(float.NaN, float.NaN); // false
AreCloseWithTolerance(float.PositiveInfinity, float.PositiveInfinity); // true

Remarks

This method handles near-zero comparisons and large magnitudes by combining relative and absolute tolerances. It is symmetric with AreCloseWithTolerance(double, double).