mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-19 08:24:00 +00:00
Make min
and max
functions variadic
This commit is contained in:
parent
3badcfe58d
commit
c7abd09aea
1 changed files with 15 additions and 2 deletions
|
@ -32,6 +32,7 @@
|
|||
#include <cmath>
|
||||
#include <cwchar>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#include "common.h"
|
||||
|
@ -195,6 +196,18 @@ static double min(double a, double b) {
|
|||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
static double maximum(const std::vector<double> &args) {
|
||||
double ret = -std::numeric_limits<double>::infinity();
|
||||
for (auto a : args) ret = max(ret, a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static double minimum(const std::vector<double> &args) {
|
||||
double ret = std::numeric_limits<double>::infinity();
|
||||
for (auto a : args) ret = min(ret, a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct te_builtin {
|
||||
const wchar_t *name;
|
||||
te_fun_t fn;
|
||||
|
@ -222,8 +235,8 @@ static const te_builtin functions[] = {
|
|||
{L"log", std::log10},
|
||||
{L"log10", std::log10},
|
||||
{L"log2", std::log2},
|
||||
{L"max", max},
|
||||
{L"min", min},
|
||||
{L"max", maximum},
|
||||
{L"min", minimum},
|
||||
{L"ncr", ncr},
|
||||
{L"npr", npr},
|
||||
{L"pi", M_PI},
|
||||
|
|
Loading…
Reference in a new issue