summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-29 22:53:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-29 22:53:35 -0700
commit5f26f2f8baaf377e414660df4e71afce9c4f4f48 (patch)
tree738831f689670ed89a983b0fcb7d272241b10781
parent8b8ca2e793f90aa58d7430b8f060c467cd41ec1b (diff)
downloadtxr-5f26f2f8baaf377e414660df4e71afce9c4f4f48.tar.gz
txr-5f26f2f8baaf377e414660df4e71afce9c4f4f48.tar.bz2
txr-5f26f2f8baaf377e414660df4e71afce9c4f4f48.zip
* lib.c (min2, max2): Semantics tweak. If the numbers are equal,
favor the left one. * txr.1: Documented min and max.
-rw-r--r--ChangeLog7
-rw-r--r--lib.c4
-rw-r--r--txr.125
3 files changed, 34 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 78c88285..644b73df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
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 <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