Comparison Operations

An expression in HCL Detect Expression Language can contain the basic comparison operations: greater than (>), greater than or equal (>=), less than (<), less than or equal (<=), equals (==), and not equals (!=) with the usual semantics. These are binary operations. With the exception of equals and not equals, they expect sub-expressions of numerical types or strings on each side. For strings, the comparison is based on lexicographic order. For equals and not equals, the left and the right sub-expressions must be of compatible types with respect to HCL Detect Expression Language coercion rules. The result of the comparison is always of type Bool.

Examples:

  • An expression using comparisons: 3>5
  • An expression using String comparisons: "abc"<"def"
  • An expression using inequality comparison: "abc"!="def"
  • An expression comparing a Double literal with a NaN (not a number) value: 10.5 != Double("nan") (Note that in this case, the math.isNaN built-in function can also be used.)
  • An expression comparing a Double literal with an Inf (positive infinity) value: 10.5 != Double("inf") (Note that in this case, the math.isPositiveInfinity built-in function can also be used.)
  • An expression comparing a Double literal with a -Inf (negative infinity) value: 10.5 != Double("-inf") (Note that in this case, the math.isNegativeInfinity built-in function can also be used.)