W3cubDocs

/Dart 2

operator == method

bool operator == (Object other)

Test whether this value is numerically equal to other.

If both operands are doubles, they are equal if they have the same representation, except that:

  • zero and minus zero (0.0 and -0.0) are considered equal. They both have the numerical value zero.
  • NaN is not equal to anything, including NaN. If either operand is NaN, the result is always false.

If one operand is a double and the other is an int, they are equal if the double has an integer value (finite with no fractional part) and identical(doubleValue.toInt(), intValue) is true.

If both operands are integers, they are equal if they have the same value.

Returns false if other is not a num.

Notice that the behavior for NaN is non-reflexive. This means that equality of double values is not a proper equality relation, as is otherwise required of operator==. Using NaN in, e.g., a HashSet will fail to work. The behavior is the standard IEEE-754 equality of doubles.

If you can avoid NaN values, the remaining doubles do have a proper equality relation, and can be used safely.

Use compareTo for a comparison that distinguishes zero and minus zero, and that considers NaN values as equal.

Implementation

bool operator ==(Object other);

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-core/num/operator_equals.html