From 1f456c71f703baf7b1b0c30f7b2062ff42ccc662 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 18 Dec 2017 11:11:04 -0800 Subject: [PATCH] [muparser] Remove MathImpl This layer of indirection is silly. --- .../include/muParserTemplateMagic.h | 40 ---------------- muparser-2.2.5/src/muParser.cpp | 47 ++++++++++--------- muparser-2.2.5/src/muParserBase.cpp | 2 +- 3 files changed, 25 insertions(+), 64 deletions(-) diff --git a/muparser-2.2.5/include/muParserTemplateMagic.h b/muparser-2.2.5/include/muParserTemplateMagic.h index f87290f2a..3cd7e3a63 100644 --- a/muparser-2.2.5/include/muParserTemplateMagic.h +++ b/muparser-2.2.5/include/muParserTemplateMagic.h @@ -3,44 +3,4 @@ #include -namespace mu { - -//----------------------------------------------------------------------------------------------- -// -// Standard math functions with dummy overload for integer types -// -//----------------------------------------------------------------------------------------------- - -/** \brief A template class for providing wrappers for essential math functions. - - This template is spezialized for several types in order to provide a unified interface - for parser internal math function calls regardless of the data type. -*/ -template -struct MathImpl { - static T Sin(T v) { return sin(v); } - static T Cos(T v) { return cos(v); } - static T Tan(T v) { return tan(v); } - static T ASin(T v) { return asin(v); } - static T ACos(T v) { return acos(v); } - static T ATan(T v) { return atan(v); } - static T ATan2(T v1, T v2) { return atan2(v1, v2); } - static T Sinh(T v) { return sinh(v); } - static T Cosh(T v) { return cosh(v); } - static T Tanh(T v) { return tanh(v); } - static T ASinh(T v) { return log(v + sqrt(v * v + 1)); } - static T ACosh(T v) { return log(v + sqrt(v * v - 1)); } - static T ATanh(T v) { return ((T)0.5 * log((1 + v) / (1 - v))); } - static T Log(T v) { return log(v); } - static T Log2(T v) { return log(v) / log((T)2); } // Logarithm base 2 - static T Log10(T v) { return log10(v); } // Logarithm base 10 - static T Exp(T v) { return exp(v); } - static T Abs(T v) { return (v >= 0) ? v : -v; } - static T Sqrt(T v) { return sqrt(v); } - static T Rint(T v) { return floor(v + (T)0.5); } - static T Sign(T v) { return (T)((v < 0) ? -1 : (v > 0) ? 1 : 0); } - static T Pow(T v1, T v2) { return std::pow(v1, v2); } -}; -} - #endif diff --git a/muparser-2.2.5/src/muParser.cpp b/muparser-2.2.5/src/muParser.cpp index 35f909412..356f48414 100644 --- a/muparser-2.2.5/src/muParser.cpp +++ b/muparser-2.2.5/src/muParser.cpp @@ -49,21 +49,19 @@ namespace mu { //--------------------------------------------------------------------------- // Trigonometric function -ValueOrError Parser::Sin(value_type v) { return MathImpl::Sin(v); } -ValueOrError Parser::Cos(value_type v) { return MathImpl::Cos(v); } -ValueOrError Parser::Tan(value_type v) { return MathImpl::Tan(v); } -ValueOrError Parser::ASin(value_type v) { return MathImpl::ASin(v); } -ValueOrError Parser::ACos(value_type v) { return MathImpl::ACos(v); } -ValueOrError Parser::ATan(value_type v) { return MathImpl::ATan(v); } -ValueOrError Parser::ATan2(value_type v1, value_type v2) { - return MathImpl::ATan2(v1, v2); -} -ValueOrError Parser::Sinh(value_type v) { return MathImpl::Sinh(v); } -ValueOrError Parser::Cosh(value_type v) { return MathImpl::Cosh(v); } -ValueOrError Parser::Tanh(value_type v) { return MathImpl::Tanh(v); } -ValueOrError Parser::ASinh(value_type v) { return MathImpl::ASinh(v); } -ValueOrError Parser::ACosh(value_type v) { return MathImpl::ACosh(v); } -ValueOrError Parser::ATanh(value_type v) { return MathImpl::ATanh(v); } +ValueOrError Parser::Sin(value_type v) { return std::sin(v); } +ValueOrError Parser::Cos(value_type v) { return std::cos(v); } +ValueOrError Parser::Tan(value_type v) { return std::tan(v); } +ValueOrError Parser::ASin(value_type v) { return std::asin(v); } +ValueOrError Parser::ACos(value_type v) { return std::acos(v); } +ValueOrError Parser::ATan(value_type v) { return std::atan(v); } +ValueOrError Parser::ATan2(value_type v1, value_type v2) { return std::atan2(v1, v2); } +ValueOrError Parser::Sinh(value_type v) { return std::sinh(v); } +ValueOrError Parser::Cosh(value_type v) { return std::cosh(v); } +ValueOrError Parser::Tanh(value_type v) { return std::tanh(v); } +ValueOrError Parser::ASinh(value_type v) { return std::asinh(v); } +ValueOrError Parser::ACosh(value_type v) { return std::acosh(v); } +ValueOrError Parser::ATanh(value_type v) { return std::atanh(v); } //--------------------------------------------------------------------------- // Logarithm functions @@ -74,7 +72,7 @@ ValueOrError Parser::Log2(value_type v) { if (v <= 0) return ParserError(ecDOMAIN_ERROR, _T("Log2")); #endif - return MathImpl::Log2(v); + return std::log2(v); } // Logarithm base 10 @@ -83,7 +81,7 @@ ValueOrError Parser::Log10(value_type v) { if (v <= 0) return ParserError(ecDOMAIN_ERROR, _T("Log10")); #endif - return MathImpl::Log10(v); + return std::log10(v); } // Logarithm base e (natural logarithm) @@ -92,22 +90,25 @@ ValueOrError Parser::Ln(value_type v) { if (v <= 0) return ParserError(ecDOMAIN_ERROR, _T("Ln")); #endif - return MathImpl::Log(v); + return std::log(v); } //--------------------------------------------------------------------------- // misc -ValueOrError Parser::Exp(value_type v) { return MathImpl::Exp(v); } -ValueOrError Parser::Abs(value_type v) { return MathImpl::Abs(v); } +ValueOrError Parser::Exp(value_type v) { return std::exp(v); } +ValueOrError Parser::Abs(value_type v) { return std::abs(v); } ValueOrError Parser::Sqrt(value_type v) { #ifdef MUP_MATH_EXCEPTIONS if (v < 0) return ParserError(ecDOMAIN_ERROR, _T("sqrt")); #endif - return MathImpl::Sqrt(v); + return std::sqrt(v); +} +ValueOrError Parser::Rint(value_type v) { return std::floor(v + 0.5); } +ValueOrError Parser::Sign(value_type v) { + // return 1, 0, -1 according to whether v is positive, zero, negative. + return (v > 0) - (v < 0); } -ValueOrError Parser::Rint(value_type v) { return MathImpl::Rint(v); } -ValueOrError Parser::Sign(value_type v) { return MathImpl::Sign(v); } //--------------------------------------------------------------------------- /** \brief Callback for the unary minus operator. diff --git a/muparser-2.2.5/src/muParserBase.cpp b/muparser-2.2.5/src/muParserBase.cpp index e49ce3bae..0d40c722a 100644 --- a/muparser-2.2.5/src/muParserBase.cpp +++ b/muparser-2.2.5/src/muParserBase.cpp @@ -788,7 +788,7 @@ ValueOrError ParserBase::ExecuteRPN() const { case cmPOW: --sidx; - Stack[sidx] = MathImpl::Pow(Stack[sidx], Stack[1 + sidx]); + Stack[sidx] = std::pow(Stack[sidx], Stack[1 + sidx]); continue; case cmLAND: