(autoconf.info)Number processing Macros


Next: Forbidden Patterns Prev: Text processing Macros Up: Programming in M4sugar

8.3.8 Arithmetic computation in M4
----------------------------------

The following macros facilitate integer arithmetic operations.  Where a
parameter is documented as taking an arithmetic expression, you can use
anything that can be parsed by `m4_eval'.

 -- Macro: m4_cmp (EXPR-1, EXPR-2)
     Compare the arithmetic expressions EXPR-1 and EXPR-2, and expand
     to `-1' if EXPR-1 is smaller, `0' if they are equal, and `1' if
     EXPR-1 is larger.

 -- Macro: m4_list_cmp (LIST-1, LIST-2)
     Compare the two M4 lists consisting of comma-separated arithmetic
     expressions, left to right.  Expand to `-1' for the first element
     pairing where the value from LIST-1 is smaller, `1' where the
     value from LIST-2 is smaller, or `0' if both lists have the same
     values.  If one list is shorter than the other, the remaining
     elements of the longer list are compared against zero.
          m4_list_cmp([1, 0],       [1])
          =>0
          m4_list_cmp([1, [1 * 0]], [1, 0])
          =>0
          m4_list_cmp([1, 2],       [1, 0])
          =>1
          m4_list_cmp([1, [1+1], 3],[1, 2])
          =>1
          m4_list_cmp([1, 2, -3],   [1, 2])
          =>-1
          m4_list_cmp([1, 0],       [1, 2])
          =>-1
          m4_list_cmp([1],          [1, 2])
          =>-1

 -- Macro: m4_max (ARG, ...)
     This macro was introduced in Autoconf 2.62.  Expand to the decimal
     value of the maximum arithmetic expression among all the arguments.

 -- Macro: m4_min (ARG, ...)
     This macro was introduced in Autoconf 2.62.  Expand to the decimal
     value of the minimum arithmetic expression among all the arguments.

 -- Macro: m4_sign (EXPR)
     Expand to `-1' if the arithmetic expression EXPR is negative, `1'
     if it is positive, and `0' if it is zero.

 -- Macro: m4_version_compare (VERSION-1, VERSION-2)
     This macro was introduced in Autoconf 2.53, but had a number of
     usability limitations that were not lifted until Autoconf 2.62.
     Compare the version strings VERSION-1 and VERSION-2, and expand to
     `-1' if VERSION-1 is smaller, `0' if they are the same, or `1'
     VERSION-2 is smaller.  Version strings must be a list of elements
     separated by `.', `,' or `-', where each element is a number along
     with optional case-insensitive letters designating beta releases.
     The comparison stops at the leftmost element that contains a
     difference, although a 0 element compares equal to a missing
     element.

     It is permissible to include commit identifiers in VERSION, such
     as an abbreviated SHA1 of the commit, provided there is still a
     monotonically increasing prefix to allow for accurate version-based
     comparisons.  For example, this paragraph was written when the
     development snapshot of autoconf claimed to be at version
     `2.61a-248-dc51', or 248 commits after the 2.61a release, with an
     abbreviated commit identification of `dc51'.

          m4_version_compare([1.1], [2.0])
          =>-1
          m4_version_compare([2.0b], [2.0a])
          =>1
          m4_version_compare([1.1.1], [1.1.1a])
          =>-1
          m4_version_compare([1.2], [1.1.1a])
          =>1
          m4_version_compare([1.0], [1])
          =>0
          m4_version_compare([1.1pre], [1.1PRE])
          =>0
          m4_version_compare([1.1a], [1,10])
          =>-1
          m4_version_compare([2.61a], [2.61a-248-dc51])
          =>-1
          m4_version_compare([2.61b], [2.61a-248-dc51])
          =>1


automatically generated by info2www