Make min and max functions variadic

This commit is contained in:
Juho Eerola 2022-01-13 04:15:45 +02:00
parent 3badcfe58d
commit c7abd09aea
No known key found for this signature in database
GPG key ID: 552C980FFBBED60E

View file

@ -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},