tinyexpr: Use cmath with std::

The oldschool math.h imports the math functions into the global
namespace, cmath imports them into std::.

Unfortunately, we already use cmath elsewhere, and including math.h
doesn't reimport them in some systems, so now they can't find them
with std::.

Fixes #7882.
This commit is contained in:
Fabian Homborg 2021-03-31 16:48:01 +02:00
parent 0c03a0267f
commit dbd608cb6a

View file

@ -27,9 +27,9 @@
#include "tinyexpr.h"
#include "wutil.h"
#include <cmath>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@ -183,52 +183,52 @@ static constexpr double bit_xor(double a, double b) {
}
static double max(double a, double b) {
if (isnan(a)) return a;
if (isnan(b)) return b;
if (a == b) return signbit(a) ? b : a; // treat +0 as larger than -0
if (std::isnan(a)) return a;
if (std::isnan(b)) return b;
if (a == b) return std::signbit(a) ? b : a; // treat +0 as larger than -0
return a > b ? a : b;
}
static double min(double a, double b) {
if (isnan(a)) return a;
if (isnan(b)) return b;
if (a == b) return signbit(a) ? a : b; // treat -0 as smaller than +0
if (std::isnan(a)) return a;
if (std::isnan(b)) return b;
if (a == b) return std::signbit(a) ? a : b; // treat -0 as smaller than +0
return a < b ? a : b;
}
static const te_builtin functions[] = {
/* must be in alphabetical order */
{L"abs", reinterpret_cast<void *>(static_cast<te_fun1>(fabs)), TE_FUNCTION1},
{L"acos", reinterpret_cast<void *>(static_cast<te_fun1>(acos)), TE_FUNCTION1},
{L"asin", reinterpret_cast<void *>(static_cast<te_fun1>(asin)), TE_FUNCTION1},
{L"atan", reinterpret_cast<void *>(static_cast<te_fun1>(atan)), TE_FUNCTION1},
{L"atan2", reinterpret_cast<void *>(static_cast<te_fun2>(atan2)), TE_FUNCTION2},
{L"abs", reinterpret_cast<void *>(static_cast<te_fun1>(std::fabs)), TE_FUNCTION1},
{L"acos", reinterpret_cast<void *>(static_cast<te_fun1>(std::acos)), TE_FUNCTION1},
{L"asin", reinterpret_cast<void *>(static_cast<te_fun1>(std::asin)), TE_FUNCTION1},
{L"atan", reinterpret_cast<void *>(static_cast<te_fun1>(std::atan)), TE_FUNCTION1},
{L"atan2", reinterpret_cast<void *>(static_cast<te_fun2>(std::atan2)), TE_FUNCTION2},
{L"bitand", reinterpret_cast<void *>(static_cast<te_fun2>(bit_and)), TE_FUNCTION2},
{L"bitor", reinterpret_cast<void *>(static_cast<te_fun2>(bit_or)), TE_FUNCTION2},
{L"bitxor", reinterpret_cast<void *>(static_cast<te_fun2>(bit_xor)), TE_FUNCTION2},
{L"ceil", reinterpret_cast<void *>(static_cast<te_fun1>(ceil)), TE_FUNCTION1},
{L"cos", reinterpret_cast<void *>(static_cast<te_fun1>(cos)), TE_FUNCTION1},
{L"cosh", reinterpret_cast<void *>(static_cast<te_fun1>(cosh)), TE_FUNCTION1},
{L"ceil", reinterpret_cast<void *>(static_cast<te_fun1>(std::ceil)), TE_FUNCTION1},
{L"cos", reinterpret_cast<void *>(static_cast<te_fun1>(std::cos)), TE_FUNCTION1},
{L"cosh", reinterpret_cast<void *>(static_cast<te_fun1>(std::cosh)), TE_FUNCTION1},
{L"e", reinterpret_cast<void *>(static_cast<te_fun0>(e)), TE_FUNCTION0},
{L"exp", reinterpret_cast<void *>(static_cast<te_fun1>(exp)), TE_FUNCTION1},
{L"exp", reinterpret_cast<void *>(static_cast<te_fun1>(std::exp)), TE_FUNCTION1},
{L"fac", reinterpret_cast<void *>(static_cast<te_fun1>(fac)), TE_FUNCTION1},
{L"floor", reinterpret_cast<void *>(static_cast<te_fun1>(floor)), TE_FUNCTION1},
{L"ln", reinterpret_cast<void *>(static_cast<te_fun1>(log)), TE_FUNCTION1},
{L"log", reinterpret_cast<void *>(static_cast<te_fun1>(log10)), TE_FUNCTION1},
{L"log10", reinterpret_cast<void *>(static_cast<te_fun1>(log10)), TE_FUNCTION1},
{L"log2", reinterpret_cast<void *>(static_cast<te_fun1>(log2)), TE_FUNCTION1},
{L"floor", reinterpret_cast<void *>(static_cast<te_fun1>(std::floor)), TE_FUNCTION1},
{L"ln", reinterpret_cast<void *>(static_cast<te_fun1>(std::log)), TE_FUNCTION1},
{L"log", reinterpret_cast<void *>(static_cast<te_fun1>(std::log10)), TE_FUNCTION1},
{L"log10", reinterpret_cast<void *>(static_cast<te_fun1>(std::log10)), TE_FUNCTION1},
{L"log2", reinterpret_cast<void *>(static_cast<te_fun1>(std::log2)), TE_FUNCTION1},
{L"max", reinterpret_cast<void *>(static_cast<te_fun2>(max)), TE_FUNCTION2},
{L"min", reinterpret_cast<void *>(static_cast<te_fun2>(min)), TE_FUNCTION2},
{L"ncr", reinterpret_cast<void *>(static_cast<te_fun2>(ncr)), TE_FUNCTION2},
{L"npr", reinterpret_cast<void *>(static_cast<te_fun2>(npr)), TE_FUNCTION2},
{L"pi", reinterpret_cast<void *>(static_cast<te_fun0>(pi)), TE_FUNCTION0},
{L"pow", reinterpret_cast<void *>(static_cast<te_fun2>(pow)), TE_FUNCTION2},
{L"round", reinterpret_cast<void *>(static_cast<te_fun1>(round)), TE_FUNCTION1},
{L"sin", reinterpret_cast<void *>(static_cast<te_fun1>(sin)), TE_FUNCTION1},
{L"sinh", reinterpret_cast<void *>(static_cast<te_fun1>(sinh)), TE_FUNCTION1},
{L"sqrt", reinterpret_cast<void *>(static_cast<te_fun1>(sqrt)), TE_FUNCTION1},
{L"tan", reinterpret_cast<void *>(static_cast<te_fun1>(tan)), TE_FUNCTION1},
{L"tanh", reinterpret_cast<void *>(static_cast<te_fun1>(tanh)), TE_FUNCTION1},
{L"pow", reinterpret_cast<void *>(static_cast<te_fun2>(std::pow)), TE_FUNCTION2},
{L"round", reinterpret_cast<void *>(static_cast<te_fun1>(std::round)), TE_FUNCTION1},
{L"sin", reinterpret_cast<void *>(static_cast<te_fun1>(std::sin)), TE_FUNCTION1},
{L"sinh", reinterpret_cast<void *>(static_cast<te_fun1>(std::sinh)), TE_FUNCTION1},
{L"sqrt", reinterpret_cast<void *>(static_cast<te_fun1>(std::sqrt)), TE_FUNCTION1},
{L"tan", reinterpret_cast<void *>(static_cast<te_fun1>(std::tan)), TE_FUNCTION1},
{L"tanh", reinterpret_cast<void *>(static_cast<te_fun1>(std::tanh)), TE_FUNCTION1},
{L"tau", reinterpret_cast<void *>(static_cast<te_fun0>(tau)), TE_FUNCTION0},
};