From 5f26f2f8baaf377e414660df4e71afce9c4f4f48 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 29 Mar 2012 22:53:35 -0700 Subject: * lib.c (min2, max2): Semantics tweak. If the numbers are equal, favor the left one. * txr.1: Documented min and max. --- ChangeLog | 7 +++++++ lib.c | 4 ++-- txr.1 | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78c88285..644b73df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-03-29 Kaz Kylheku + + * 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 * arith.c (numeq): New function. diff --git a/lib.c b/lib.c index d354ce6e..eb756086 100644 --- a/lib.c +++ b/lib.c @@ -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) diff --git a/txr.1 b/txr.1 index d104df86..13724a41 100644 --- a/txr.1 +++ b/txr.1 @@ -7087,6 +7087,31 @@ character will convert to integer. .SS Functions max and min +.TP +Syntax: + + (max *) + (min *) + +.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 -- cgit v1.2.3