Skip to main content
The >= (greater than or equal to) operator is a binary relational operator that evaluates whether the left-hand operand is numerically greater than or equivalent to the right-hand operand. It returns a boolean result.

Syntax

bool result = leftOperand >= rightOperand;

Semantics

  1. Evaluation: The operator compares the numeric value of leftOperand against rightOperand.
  2. Return Value:
    • Returns true if leftOperand is strictly greater than rightOperand.
    • Returns true if leftOperand is numerically equal to rightOperand.
    • Returns false if leftOperand is strictly less than rightOperand.
  3. Type Interoperability: The standard implementation supports comparisons between int and double types via the num class.

Standard Numeric Implementation

When applied to standard Dart numeric types (int, double), the operator adheres to standard arithmetic comparison rules.
void main() {
  // Integer comparison
  print(5 >= 3);  // true
  print(5 >= 5);  // true
  print(2 >= 5);  // false

  // Double comparison
  print(4.5 >= 4.2); // true

  // Mixed type comparison (int and double)
  print(5 >= 5.0); // true
  print(5 >= 5.1); // false
}

Operator Overloading

Dart allows classes to define custom behavior for the >= operator by overriding the operator >= method. The method must accept a single argument and typically returns a bool. To implement this, a class must define the following signature:
class Vector {
  final int magnitude;

  Vector(this.magnitude);

  // Overriding the >= operator
  bool operator >=(Vector other) {
    return this.magnitude >= other.magnitude;
  }
}

void main() {
  final v1 = Vector(10);
  final v2 = Vector(5);

  // Invokes v1.operator>=(v2)
  print(v1 >= v2); // true
}

IEEE 754 Floating-Point Behavior

When comparing double values involving NaN (Not a Number), the >= operator follows IEEE 754 standards. Any relational comparison involving NaN returns false.
double nanValue = double.nan;

print(nanValue >= 5);       // false
print(5 >= nanValue);       // false
print(nanValue >= nanValue); // false
Master Dart with Deep Grasping Methodology!Learn More