Extend max/min to cover an explicit list of values.

This commit is contained in:
Glen Whitney 2019-07-29 12:42:51 -04:00
parent 9caf9bf1a5
commit 1114df2e13
2 changed files with 102 additions and 7 deletions

View file

@ -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;
}
/*}}}*/