Skip to content

COMPARE Expression

COMPARE compares one or more numeric or text values and returns 1 for true or 0 for false.

Syntax

COMPARE{NUM;operator;arg1,arg2,arg3,...}
COMPARE{TXT;operator;arg1,arg2,arg3,...}

NUM and TXT are the exact production mode names and are case-sensitive.

Supported operators are:

==  !=  <  <=  >  >=

Nested ACE expressions in the argument list are resolved before COMPARE itself is evaluated; COMPARE is not lazy control flow.

Numeric mode

With NUM, every argument is parsed as a number.

For multiple values:

  • == is true when every value equals the first value;
  • != is true when at least one later value differs from the first value;
  • < requires a strictly increasing sequence;
  • <= requires a non-decreasing sequence;
  • > requires a strictly decreasing sequence;
  • >= requires a non-increasing sequence.

Examples already present in ACE's reference/tests:

COMPARE{NUM;==;9,CALC{1+POW{2,3}}}                         -> 1
COMPARE{NUM;==;9,CALC{1+POW{2,3}},CALC{(27/3)-1}}          -> 0

Text mode

With TXT, == and != compare string content. The ordering operators <, <=, >, and >= compare std::string::length() values, not alphabetical/lexicographical order. For multiple values, the same sequence rules described above are applied to those lengths.

Existing examples:

COMPARE{TXT;==;text,text}                 -> 1
COMPARE{TXT;==;auto bus,auto sub}         -> 0

A single comparison argument is considered true by the production implementation, regardless of the selected operator.