diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib.c | 4 | ||||
-rw-r--r-- | txr.1 | 25 |
3 files changed, 34 insertions, 2 deletions
@@ -1,5 +1,12 @@ 2012-03-29 Kaz Kylheku <kaz@kylheku.com> + * lib.c (min2, max2): Semantics tweak. If the numbers are equal, + favor the left one. + + * txr.1: Documented min and max. + +2012-03-29 Kaz Kylheku <kaz@kylheku.com> + * arith.c (numeq): New function. (exptmod): Bugfix: was no normalizing the bignum, ouch. Also was reporting "non-integral operands" for other @@ -1285,12 +1285,12 @@ val numeqv(val first, val rest) val max2(val anum, val bnum) { - return if3(gt(anum, bnum), anum, bnum); + return if3(ge(anum, bnum), anum, bnum); } val min2(val anum, val bnum) { - return if3(lt(anum, bnum), anum, bnum); + return if3(le(anum, bnum), anum, bnum); } val maxv(val first, val rest) @@ -7087,6 +7087,31 @@ character will convert to integer. .SS Functions max and min +.TP +Syntax: + + (max <number> <number>*) + (min <number> <number>*) + +.TP +Description: + +The max and min functions determine and return the highest or lowest +value from among their arguments. + +The arguments must be numbers or characters. + +If only a single argument is given, that value is returned. + +If two arguments are given, then (max a b) is equivalent to (if (>= a b) a b), +and (min a b) is equivalent to (if (<= a b) a b). If the operands do not +have the same type, then one of them is converted to the type of the other; +however, the original unconverted values are returned. For instance +(max 4 3.0) yields the integer 4, not 4.0. + +If three or more arguments are given, max and min are left-associative. +Thus (max a b c) is (max (max a b) c). + .SS Functions search-regex and match-regex .SS Function regsub |