System.Double.Equals Method

Returns a value indicating whether this instance is equal to a specified object.

Syntax

public override bool Equals (object obj)

Parameters

obj
An object to compare with this instance.

Returns

true if obj is an instance of double and equals the value of this instance; otherwise, false.

Remarks

The double.Equals(double) method should be used with caution, because two apparently equivalent values can be unequal due to the differing precision of the two values. The following example reports that the double value .3333 and the double returned by dividing 1 by 3 are unequal.

code reference: System.Double.Epsilon#3

For alternatives to calling the double.Equals(object) method, see the documentation for the double.Equals(double) overload.

Note:

Because double.Epsilon defines the minimum expression of a positive value whose range is near zero, the margin of difference between two similar values must be greater than double.Epsilon. Typically, it is many times greater than double.Epsilon.

The precision of floating-point numbers beyond the documented precision is specific to the implementation and version of the .NET Framework. Consequently, a comparison of two particular numbers might change between versions of the .NET Framework because the precision of the numbers' internal representation might change.

If two double.NaN values are tested for equality by calling the double.Equals(double) method, the method returns true. However, if two double.NaN values are tested for equality by using the equality operator, the operator returns false. When you want to determine whether the value of a double is not a number (NaN), an alternative is to call the double.IsNaN(double) method.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0