diff --git a/doc/teapot.lyx b/doc/teapot.lyx index f30270d..694bdf7 100644 --- a/doc/teapot.lyx +++ b/doc/teapot.lyx @@ -6338,7 +6338,46 @@ location l2 \emph default -) +) +\emph on + +\begin_inset space ~ +\end_inset + + +\emph default +| +\emph on + +\begin_inset space ~ +\end_inset + + +\series default +\emph default +max +\series medium +( +\emph on +v1 +\emph default +, +\begin_inset space ~ +\end_inset + + +\emph on +v2 +\emph default +, +\emph on + +\begin_inset space ~ +\end_inset + + +\emph default +...) \series default evaluates to the maximum in the same way min does for the minimum. @@ -6376,9 +6415,48 @@ location l2 \emph default ) +\emph on + +\begin_inset space ~ +\end_inset + + +\emph default +| +\emph on + +\begin_inset space ~ +\end_inset + + \series default - evaluates to the location of the minimum of all values in the block marked - by the corners pointed to by +\emph default +min +\series medium +( +\emph on +v1 +\emph default +, +\begin_inset space ~ +\end_inset + + +\emph on +v2 +\emph default +, +\emph on + +\begin_inset space ~ +\end_inset + + +\emph default +...) +\series default + The first form evaluates to the location of the minimum of all values in + the block marked by the corners pointed to by \emph on l1 \emph default @@ -6399,7 +6477,9 @@ l1 l2 \emph default )). - + The second form simply returns the smallest of the specified values, returning + an error if it encounters two that are not comparable (like a string and + an integer). \end_layout \begin_layout Description diff --git a/src/common/func.c b/src/common/func.c index db1d801..8621a9f 100644 --- a/src/common/func.c +++ b/src/common/func.c @@ -915,7 +915,7 @@ static Token log_func(int argc, const Token argv[]) static Token minmax_func(int argc, const Token argv[], int min) { /* variables */ /*{{{*/ - Token result; + Token result, tmp; Location minloc; /*}}}*/ @@ -926,7 +926,6 @@ static Token minmax_func(int argc, const Token argv[], int min) Location w; int x1,y1,z1; int x2,y2,z2; - Token tmp; /*}}}*/ x1=argv[0].u.location[0]; x2=argv[1].u.location[0]; posorder(&x1,&x2); @@ -972,11 +971,27 @@ static Token minmax_func(int argc, const Token argv[], int min) return result; } /*}}}*/ + else if (argc > 0) /* try to take min/max of all arguments */ + { + size_t i, mini; + mini = 0; + for (i = 1; i < argc; ++i) { + tmp = (min ? tlt(argv[i], argv[mini]) : tgt(argv[i], argv[mini])); + if (tmp.type == INT) /* comparison succeeded */ + { + if (tmp.u.integer) mini = i; + tfree(&tmp); + } + else /* failed comparison, return the error */ + return tmp; + } + return argv[mini]; + } else /* result is min/max type error */ /*{{{*/ { result.type=EEK; - result.u.err=mystrmalloc(min ? _("Usage: min(location,location)") : _("Usage: max(location,location)")); + result.u.err=mystrmalloc(min ? _("Usage: min(location,location) or min(val1, val2,...)") : _("Usage: max(location,location) or max(val1,val2,...)")); return result; } /*}}}*/