New to Telerik UI for WinFormsStart a free 30-day trial

Provides utility methods for floating-point number comparisons and operations with epsilon tolerance.

Definition

Namespace:Telerik.WinControls

Assembly:Telerik.WinControls.dll

Syntax:

C#
public static class DoubleUtil

Inheritance: objectDoubleUtil

Methods

Determines whether two float values are close enough to be considered equal within epsilon tolerance.

C#
public static bool AreClose(float value1, float value2)
Parameters:value1float

The first float value to compare.

value2float

The second float value to compare.

Returns:

bool

true if the values are close enough to be considered equal; otherwise, false.

Remarks:

This method accounts for floating-point precision errors by using an epsilon tolerance value that adjusts based on the magnitude of the numbers being compared.

Determines whether two PointF structures are close enough to be considered equal within epsilon tolerance.

C#
public static bool AreClose(PointF point1, PointF point2)
Parameters:point1PointF

The first PointF to compare.

point2PointF

The second PointF to compare.

Returns:

bool

true if both X and Y coordinates are close enough to be considered equal; otherwise, false.

Determines whether two RectangleF structures are close enough to be considered equal within epsilon tolerance.

C#
public static bool AreClose(RectangleF rect1, RectangleF rect2)
Parameters:rect1RectangleF

The first RectangleF to compare.

rect2RectangleF

The second RectangleF to compare.

Returns:

bool

true if all rectangle properties (X, Y, Width, Height) are close enough to be considered equal; otherwise, false.

Remarks:

Empty rectangles are compared for exact emptiness rather than using epsilon tolerance.

Determines whether two SizeF structures are close enough to be considered equal within epsilon tolerance.

C#
public static bool AreClose(SizeF size1, SizeF size2)
Parameters:size1SizeF

The first SizeF to compare.

size2SizeF

The second SizeF to compare.

Returns:

bool

true if both Width and Height values are close enough to be considered equal; otherwise, false.

Remarks:

This method compares both the Width and Height properties of the size structures using epsilon tolerance to account for floating-point precision errors.

Converts a float value to an integer using proper rounding.

C#
public static int DoubleToInt(float val)
Parameters:valfloat

The float value to convert.

Returns:

int

The rounded integer value.

Remarks:

This method performs proper rounding by adding or subtracting 0.5 based on the sign of the value before truncating to integer. This ensures consistent rounding behavior compared to simple casting.

For positive values, 0.5 is added before truncation. For negative values, 0.5 is subtracted. This provides symmetrical rounding around zero.

Determines whether the first value is greater than the second value with epsilon tolerance.

C#
public static bool GreaterThan(float value1, float value2)
Parameters:value1float

The first value to compare.

value2float

The second value to compare.

Returns:

bool

true if value1 is greater than value2 and they are not close enough to be equal; otherwise, false.

Remarks:

This method returns true only if value1 is definitively greater than value2, taking into account floating-point precision. Values that are close enough to be considered equal will return false.

Determines whether the first value is greater than or approximately equal to the second value.

C#
public static bool GreaterThanOrClose(float value1, float value2)
Parameters:value1float

The first value to compare.

value2float

The second value to compare.

Returns:

bool

true if value1 is greater than value2 or they are close enough to be considered equal; otherwise, false.

Remarks:

This method returns true if value1 is either definitively greater than value2 or if they are close enough to be considered equal within epsilon tolerance.

Determines whether a value is between 0 and 1 (inclusive) using epsilon tolerance.

C#
public static bool IsBetweenZeroAndOne(float val)
Parameters:valfloat

The value to check.

Returns:

bool

true if the value is greater than or equal to 0 and less than or equal to 1 (within epsilon tolerance); otherwise, false.

Remarks:

This method is commonly used for validating normalized values, percentages, and alpha values that should be constrained to the 0-1 range.

C#
public static bool IsLessThan(double value1, double value2)
Parameters:value1doublevalue2doubleReturns:

bool

C#
public static bool IsNaN(float value)
Parameters:valuefloatReturns:

bool

Determines whether a float value is approximately equal to 1.0 within epsilon tolerance.

C#
public static bool IsOne(float value)
Parameters:valuefloat

The value to check.

Returns:

bool

true if the value is close enough to 1.0 to be considered equal; otherwise, false.

Remarks:

This method uses a tighter epsilon tolerance (10 times the base epsilon) to determine if a value represents unity, accounting for floating-point precision errors.

Determines whether a float value is approximately equal to 0.0 within epsilon tolerance.

C#
public static bool IsZero(float value)
Parameters:valuefloat

The value to check.

Returns:

bool

true if the value is close enough to 0.0 to be considered equal; otherwise, false.

Remarks:

This method uses a tighter epsilon tolerance (10 times the base epsilon) to determine if a value represents zero, accounting for floating-point precision errors.

C#
public static bool LessThan(double value1, double value2)
Parameters:value1doublevalue2doubleReturns:

bool

C#
public static bool LessThan(float value1, float value2)
Parameters:value1floatvalue2floatReturns:

bool

C#
public static bool LessThanOrClose(float value1, float value2)
Parameters:value1floatvalue2floatReturns:

bool