From dbd608cb6ab1380038311fd8d6357a06be6c7b7f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 31 Mar 2021 16:48:01 +0200 Subject: [PATCH] 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. --- src/tinyexpr.cpp | 56 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index 1dc8165d1..dc3afe254 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -27,9 +27,9 @@ #include "tinyexpr.h" #include "wutil.h" +#include #include #include -#include #include #include @@ -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(static_cast(fabs)), TE_FUNCTION1}, - {L"acos", reinterpret_cast(static_cast(acos)), TE_FUNCTION1}, - {L"asin", reinterpret_cast(static_cast(asin)), TE_FUNCTION1}, - {L"atan", reinterpret_cast(static_cast(atan)), TE_FUNCTION1}, - {L"atan2", reinterpret_cast(static_cast(atan2)), TE_FUNCTION2}, + {L"abs", reinterpret_cast(static_cast(std::fabs)), TE_FUNCTION1}, + {L"acos", reinterpret_cast(static_cast(std::acos)), TE_FUNCTION1}, + {L"asin", reinterpret_cast(static_cast(std::asin)), TE_FUNCTION1}, + {L"atan", reinterpret_cast(static_cast(std::atan)), TE_FUNCTION1}, + {L"atan2", reinterpret_cast(static_cast(std::atan2)), TE_FUNCTION2}, {L"bitand", reinterpret_cast(static_cast(bit_and)), TE_FUNCTION2}, {L"bitor", reinterpret_cast(static_cast(bit_or)), TE_FUNCTION2}, {L"bitxor", reinterpret_cast(static_cast(bit_xor)), TE_FUNCTION2}, - {L"ceil", reinterpret_cast(static_cast(ceil)), TE_FUNCTION1}, - {L"cos", reinterpret_cast(static_cast(cos)), TE_FUNCTION1}, - {L"cosh", reinterpret_cast(static_cast(cosh)), TE_FUNCTION1}, + {L"ceil", reinterpret_cast(static_cast(std::ceil)), TE_FUNCTION1}, + {L"cos", reinterpret_cast(static_cast(std::cos)), TE_FUNCTION1}, + {L"cosh", reinterpret_cast(static_cast(std::cosh)), TE_FUNCTION1}, {L"e", reinterpret_cast(static_cast(e)), TE_FUNCTION0}, - {L"exp", reinterpret_cast(static_cast(exp)), TE_FUNCTION1}, + {L"exp", reinterpret_cast(static_cast(std::exp)), TE_FUNCTION1}, {L"fac", reinterpret_cast(static_cast(fac)), TE_FUNCTION1}, - {L"floor", reinterpret_cast(static_cast(floor)), TE_FUNCTION1}, - {L"ln", reinterpret_cast(static_cast(log)), TE_FUNCTION1}, - {L"log", reinterpret_cast(static_cast(log10)), TE_FUNCTION1}, - {L"log10", reinterpret_cast(static_cast(log10)), TE_FUNCTION1}, - {L"log2", reinterpret_cast(static_cast(log2)), TE_FUNCTION1}, + {L"floor", reinterpret_cast(static_cast(std::floor)), TE_FUNCTION1}, + {L"ln", reinterpret_cast(static_cast(std::log)), TE_FUNCTION1}, + {L"log", reinterpret_cast(static_cast(std::log10)), TE_FUNCTION1}, + {L"log10", reinterpret_cast(static_cast(std::log10)), TE_FUNCTION1}, + {L"log2", reinterpret_cast(static_cast(std::log2)), TE_FUNCTION1}, {L"max", reinterpret_cast(static_cast(max)), TE_FUNCTION2}, {L"min", reinterpret_cast(static_cast(min)), TE_FUNCTION2}, {L"ncr", reinterpret_cast(static_cast(ncr)), TE_FUNCTION2}, {L"npr", reinterpret_cast(static_cast(npr)), TE_FUNCTION2}, {L"pi", reinterpret_cast(static_cast(pi)), TE_FUNCTION0}, - {L"pow", reinterpret_cast(static_cast(pow)), TE_FUNCTION2}, - {L"round", reinterpret_cast(static_cast(round)), TE_FUNCTION1}, - {L"sin", reinterpret_cast(static_cast(sin)), TE_FUNCTION1}, - {L"sinh", reinterpret_cast(static_cast(sinh)), TE_FUNCTION1}, - {L"sqrt", reinterpret_cast(static_cast(sqrt)), TE_FUNCTION1}, - {L"tan", reinterpret_cast(static_cast(tan)), TE_FUNCTION1}, - {L"tanh", reinterpret_cast(static_cast(tanh)), TE_FUNCTION1}, + {L"pow", reinterpret_cast(static_cast(std::pow)), TE_FUNCTION2}, + {L"round", reinterpret_cast(static_cast(std::round)), TE_FUNCTION1}, + {L"sin", reinterpret_cast(static_cast(std::sin)), TE_FUNCTION1}, + {L"sinh", reinterpret_cast(static_cast(std::sinh)), TE_FUNCTION1}, + {L"sqrt", reinterpret_cast(static_cast(std::sqrt)), TE_FUNCTION1}, + {L"tan", reinterpret_cast(static_cast(std::tan)), TE_FUNCTION1}, + {L"tanh", reinterpret_cast(static_cast(std::tanh)), TE_FUNCTION1}, {L"tau", reinterpret_cast(static_cast(tau)), TE_FUNCTION0}, };