Navigation

Operators and Keywords

Function List:

C++ API

: compare_versions (v1, v2, operator)

Compare two version strings using the given operator.

This function assumes that versions v1 and v2 are arbitrarily long strings made of numeric and period characters possibly followed by an arbitrary string (e.g., "1.2.3", "0.3", "0.1.2+", or "1.2.3.4-test1").

The version is first split into numeric and character portions and then the parts are padded to be the same length (i.e., "1.1" would be padded to be "1.1.0" when being compared with "1.1.1", and separately, the character parts of the strings are padded with nulls).

The operator can be any logical operator from the set

  • "==" equal
  • "<" less than
  • "<=" less than or equal to
  • ">" greater than
  • ">=" greater than or equal to
  • "!=" not equal
  • "~=" not equal

Note that version "1.1-test2" will compare as greater than "1.1-test10". Also, since the numeric part is compared first, "a" compares less than "1a" because the second string starts with a numeric part even though double ("a") is greater than double ("1").

Package: octave