skip navigation
  • Product Bundles

    DevCraft

    All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:

    • AI Coding Assistants
    • Embedded Reporting
    • Document Processing Libraries
    • SSO Account Sign-in

    Web

    Kendo UI UI for Angular UI for Vue UI for jQuery KendoReact UI for Blazor UI for ASP.NET Core UI for ASP.NET MVC UI for ASP.NET AJAX

    Mobile

    UI for .NET MAUI

    Document Management

    Telerik Document Processing

    Desktop

    UI for .NET MAUI UI for WinUI UI for WinForms UI for WPF

    Reporting

    Telerik Reporting Telerik Report Server

    Testing & Mocking

    Test Studio Telerik JustMock

    CMS

    Sitefinity

    AI Productivity Tools

    AI Coding Assistants

    UI/UX Tools

    ThemeBuilder Design System Kit Templates and Building Blocks

    Debugging

    Fiddler Fiddler Everywhere Fiddler Classic Fiddler Everywhere Reporter FiddlerCore

    Free Tools

    KendoReact Free VB.NET to C# Converter Testing Framework
    View all products
  • Overview
  • Demos
    • What's New
    • Roadmap
    • Release History
  • Support and Learning

    • Support and Learning Hub
    • First Steps
    • Docs
    • Demos
    • Virtual Classroom
    • Forums
    • Videos
    • Blogs
    • Accessibility
    • Submit a Ticket

    Productivity and Design Tools

    • Visual Studio Extensions
    • Visual Studio Templates
    • Embedded Reporting
  • Pricing
  • Shopping cart
    • Account Overview
    • Your Licenses
    • Downloads
    • Support Center
    • Forum Profile
    • Payment Methods
    • Edit Profile
    • Log out
  • Login
  • Contact Us
  • Try now

Class DoubleUtil

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

Inheritance
System.Object
DoubleUtil
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Telerik.WinControls
Assembly: Telerik.WinControls.dll

Syntax

public static class DoubleUtil
Remarks

DoubleUtil addresses the common problem of floating-point precision errors by providing comparison methods that use an epsilon tolerance value. This is essential for reliable comparisons in graphics and layout calculations where small rounding errors can occur.

The class provides methods for comparing float values, points, rectangles, and sizes with appropriate tolerance for equality, greater-than, and less-than operations. It also includes utility methods for safe float-to-integer conversion.

This utility is used throughout the Telerik WinControls framework for layout calculations, hit testing, and other operations that require robust floating-point comparisons.

Methods

AreClose(PointF, PointF)

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

Declaration
public static bool AreClose(PointF point1, PointF point2)
Parameters
System.Drawing.PointF point1

The first PointF to compare.

System.Drawing.PointF point2

The second PointF to compare.

Returns
System.Boolean

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

AreClose(RectangleF, RectangleF)

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

Declaration
public static bool AreClose(RectangleF rect1, RectangleF rect2)
Parameters
System.Drawing.RectangleF rect1

The first RectangleF to compare.

System.Drawing.RectangleF rect2

The second RectangleF to compare.

Returns
System.Boolean

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.

AreClose(SizeF, SizeF)

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

Declaration
public static bool AreClose(SizeF size1, SizeF size2)
Parameters
System.Drawing.SizeF size1

The first SizeF to compare.

System.Drawing.SizeF size2

The second SizeF to compare.

Returns
System.Boolean

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.

AreClose(Single, Single)

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

Declaration
public static bool AreClose(float value1, float value2)
Parameters
System.Single value1

The first float value to compare.

System.Single value2

The second float value to compare.

Returns
System.Boolean

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.

DoubleToInt(Single)

Converts a float value to an integer using proper rounding.

Declaration
public static int DoubleToInt(float val)
Parameters
System.Single val

The float value to convert.

Returns
System.Int32

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.

GreaterThan(Single, Single)

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

Declaration
public static bool GreaterThan(float value1, float value2)
Parameters
System.Single value1

The first value to compare.

System.Single value2

The second value to compare.

Returns
System.Boolean

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.

GreaterThanOrClose(Single, Single)

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

Declaration
public static bool GreaterThanOrClose(float value1, float value2)
Parameters
System.Single value1

The first value to compare.

System.Single value2

The second value to compare.

Returns
System.Boolean

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.

IsBetweenZeroAndOne(Single)

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

Declaration
public static bool IsBetweenZeroAndOne(float val)
Parameters
System.Single val

The value to check.

Returns
System.Boolean

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.

IsLessThan(Double, Double)

Declaration
public static bool IsLessThan(double value1, double value2)
Parameters
System.Double value1

System.Double value2

Returns
System.Boolean

IsNaN(Single)

Declaration
public static bool IsNaN(float value)
Parameters
System.Single value

Returns
System.Boolean

IsOne(Single)

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

Declaration
public static bool IsOne(float value)
Parameters
System.Single value

The value to check.

Returns
System.Boolean

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.

IsZero(Single)

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

Declaration
public static bool IsZero(float value)
Parameters
System.Single value

The value to check.

Returns
System.Boolean

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.

LessThan(Double, Double)

Declaration
public static bool LessThan(double value1, double value2)
Parameters
System.Double value1

System.Double value2

Returns
System.Boolean

LessThan(Single, Single)

Declaration
public static bool LessThan(float value1, float value2)
Parameters
System.Single value1

System.Single value2

Returns
System.Boolean

LessThanOrClose(Single, Single)

Declaration
public static bool LessThanOrClose(float value1, float value2)
Parameters
System.Single value1

System.Single value2

Returns
System.Boolean

Getting Started
  • Install Now
  • Demos
  • Step-by-Step Tutorial
  • Sample Applications
  • SDK Samples
  • Visual Studio Extensions
Support Resources
  • Code Library
  • Knowledge Base
  • Videos
Community
  • Forums
  • Blogs
  • Feedback Portal
  • Document Processing Feedback Portal

Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.