From 73c035ecc963e980156d84960472ea5916c6fa80 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 14 Apr 2017 18:42:49 +0300 Subject: [PATCH] Fix bug with trigonometric functions. Functions sin(), cos() and tan() take radians. And their counterparts asin(), acos() and atan() return radians. Removed hyperbolic functions because they do not work with radians. --HG-- branch : release --- src/libs/qmuparser/qmuparser.cpp | 72 ++++++-------------------- src/libs/qmuparser/qmuparser.h | 6 --- src/libs/vmisc/def.cpp | 7 --- src/libs/vmisc/def.h | 6 --- src/libs/vpatterndb/vtranslatevars.cpp | 18 +++---- 5 files changed, 21 insertions(+), 88 deletions(-) diff --git a/src/libs/qmuparser/qmuparser.cpp b/src/libs/qmuparser/qmuparser.cpp index 35f489bf6..dc2effcf8 100644 --- a/src/libs/qmuparser/qmuparser.cpp +++ b/src/libs/qmuparser/qmuparser.cpp @@ -62,76 +62,40 @@ qreal QmuParser::Sinh(qreal v) return sinh(v); } -//--------------------------------------------------------------------------------------------------------------------- -qreal QmuParser::Cosh(qreal v) -{ - return cosh(v); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal QmuParser::Tanh(qreal v) -{ - return tanh(v); -} - //--------------------------------------------------------------------------------------------------------------------- qreal QmuParser::ASinh(qreal v) { return log(v + qSqrt(v * v + 1)); } +//--------------------------------------------------------------------------------------------------------------------- +qreal QmuParser::Cosh(qreal v) +{ + return cosh(v); +} + //--------------------------------------------------------------------------------------------------------------------- qreal QmuParser::ACosh(qreal v) { return log(v + qSqrt(v * v - 1)); } +//--------------------------------------------------------------------------------------------------------------------- +qreal QmuParser::Tanh(qreal v) +{ + return tanh(v); +} + //--------------------------------------------------------------------------------------------------------------------- qreal QmuParser::ATanh(qreal v) { return (0.5 * log((1 + v) / (1 - v))); } -//--------------------------------------------------------------------------------------------------------------------- -qreal QmuParser::SinhD(qreal v) -{ - return qRadiansToDegrees(sinh(v)); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal QmuParser::CoshD(qreal v) -{ - return qRadiansToDegrees(cosh(v)); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal QmuParser::TanhD(qreal v) -{ - return qRadiansToDegrees(tanh(v)); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal QmuParser::ASinhD(qreal v) -{ - return qRadiansToDegrees(log(v + qSqrt(v * v + 1))); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal QmuParser::ACoshD(qreal v) -{ - return qRadiansToDegrees(log(v + qSqrt(v * v - 1))); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal QmuParser::ATanhD(qreal v) -{ - return qRadiansToDegrees(0.5 * log((1 + v) / (1 - v))); -} - //--------------------------------------------------------------------------------------------------------------------- qreal QmuParser::SinD(qreal v) { - return qRadiansToDegrees(qSin(v)); + return qSin(qDegreesToRadians(v)); } //--------------------------------------------------------------------------------------------------------------------- @@ -143,7 +107,7 @@ qreal QmuParser::ASinD(qreal v) //--------------------------------------------------------------------------------------------------------------------- qreal QmuParser::CosD(qreal v) { - return qRadiansToDegrees(qCos(v)); + return qCos(qDegreesToRadians(v)); } //--------------------------------------------------------------------------------------------------------------------- @@ -155,7 +119,7 @@ qreal QmuParser::ACosD(qreal v) //--------------------------------------------------------------------------------------------------------------------- qreal QmuParser::TanD(qreal v) { - return qRadiansToDegrees(qTan(v)); + return qTan(qDegreesToRadians(v)); } //--------------------------------------------------------------------------------------------------------------------- @@ -387,16 +351,10 @@ void QmuParser::InitFun() DefineFun("sinh", Sinh); DefineFun("cosh", Cosh); DefineFun("tanh", Tanh); - DefineFun("sinhD", SinhD); - DefineFun("coshD", CoshD); - DefineFun("tanhD", TanhD); // arcus hyperbolic functions DefineFun("asinh", ASinh); DefineFun("acosh", ACosh); DefineFun("atanh", ATanh); - DefineFun("asinhD", ASinhD); - DefineFun("acoshD", ACoshD); - DefineFun("atanhD", ATanhD); // Logarithm functions DefineFun("log2", Log2); DefineFun("log10", Log10); diff --git a/src/libs/qmuparser/qmuparser.h b/src/libs/qmuparser/qmuparser.h index 1b98bee51..ede6284bf 100644 --- a/src/libs/qmuparser/qmuparser.h +++ b/src/libs/qmuparser/qmuparser.h @@ -77,12 +77,6 @@ namespace qmu static qreal ASinD(qreal); static qreal ACosD(qreal); static qreal ATanD(qreal); - static qreal SinhD(qreal); - static qreal CoshD(qreal); - static qreal TanhD(qreal); - static qreal ASinhD(qreal); - static qreal ACoshD(qreal); - static qreal ATanhD(qreal); // Logarithm functions static qreal Log2(qreal); // Logarithm Base 2 diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 67b7ba3d7..9353d6f1d 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -402,12 +402,6 @@ const QString tanD_F = QStringLiteral("tanD"); const QString asinD_F = QStringLiteral("asinD"); const QString acosD_F = QStringLiteral("acosD"); const QString atanD_F = QStringLiteral("atanD"); -const QString sinhD_F = QStringLiteral("sinhD"); -const QString coshD_F = QStringLiteral("coshD"); -const QString tanhD_F = QStringLiteral("tanhD"); -const QString asinhD_F = QStringLiteral("asinhD"); -const QString acoshD_F = QStringLiteral("acoshD"); -const QString atanhD_F = QStringLiteral("atanhD"); const QString log2_F = QStringLiteral("log2"); const QString log10_F = QStringLiteral("log10"); const QString log_F = QStringLiteral("log"); @@ -427,7 +421,6 @@ const QStringList builInFunctions = QStringList() << degTorad_F << radTodeg_F << sin_F << cos_F << tan_F << asin_F << acos_F << atan_F << sinh_F << cosh_F << tanh_F << asinh_F << acosh_F << atanh_F << sinD_F << cosD_F << tanD_F << asinD_F << acosD_F << atanD_F - << sinhD_F << coshD_F << tanhD_F << asinhD_F << acoshD_F << atanhD_F << log2_F << log10_F << log_F << ln_F << exp_F << sqrt_F << sign_F << rint_F << abs_F << min_F << max_F << sum_F << avg_F << fmod_F; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index e52b2ef22..af1fb56d4 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -657,12 +657,6 @@ extern const QString tanD_F; extern const QString asinD_F; extern const QString acosD_F; extern const QString atanD_F; -extern const QString sinhD_F; -extern const QString coshD_F; -extern const QString tanhD_F; -extern const QString asinhD_F; -extern const QString acoshD_F; -extern const QString atanhD_F; extern const QString log2_F; extern const QString log10_F; extern const QString log_F; diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index e6823dc9f..d0cd0a39c 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -411,24 +411,18 @@ void VTranslateVars::InitFunctions() functions.insert(asin_F, translate("VTranslateVars", "asin", "arcus sine function working with radians")); functions.insert(acos_F, translate("VTranslateVars", "acos", "arcus cosine function working with radians")); functions.insert(atan_F, translate("VTranslateVars", "atan", "arcus tangens function working with radians")); - functions.insert(sinh_F, translate("VTranslateVars", "sinh", "hyperbolic sine function working with radians")); - functions.insert(cosh_F, translate("VTranslateVars", "cosh", "hyperbolic cosine working with radians")); - functions.insert(tanh_F, translate("VTranslateVars", "tanh", "hyperbolic tangens function working with radians")); - functions.insert(asinh_F, translate("VTranslateVars", "asinh", "hyperbolic arcus sine function working with radians")); - functions.insert(acosh_F, translate("VTranslateVars", "acosh", "hyperbolic arcus cosine function working with radians")); - functions.insert(atanh_F, translate("VTranslateVars", "atanh", "hyperbolic arcur tangens function working with radians")); + functions.insert(sinh_F, translate("VTranslateVars", "sinh", "hyperbolic sine function")); + functions.insert(cosh_F, translate("VTranslateVars", "cosh", "hyperbolic cosine")); + functions.insert(tanh_F, translate("VTranslateVars", "tanh", "hyperbolic tangens function")); + functions.insert(asinh_F, translate("VTranslateVars", "asinh", "hyperbolic arcus sine function")); + functions.insert(acosh_F, translate("VTranslateVars", "acosh", "hyperbolic arcus cosine function")); + functions.insert(atanh_F, translate("VTranslateVars", "atanh", "hyperbolic arcur tangens function")); functions.insert(sinD_F, translate("VTranslateVars", "sinD", "sine function working with degrees")); functions.insert(cosD_F, translate("VTranslateVars", "cosD", "cosine function working with degrees")); functions.insert(tanD_F, translate("VTranslateVars", "tanD", "tangens function working with degrees")); functions.insert(asinD_F, translate("VTranslateVars", "asinD", "arcus sine function working with degrees")); functions.insert(acosD_F, translate("VTranslateVars", "acosD", "arcus cosine function working with degrees")); functions.insert(atanD_F, translate("VTranslateVars", "atanD", "arcus tangens function working with degrees")); - functions.insert(sinhD_F, translate("VTranslateVars", "sinhD", "hyperbolic sine function working with degrees")); - functions.insert(coshD_F, translate("VTranslateVars", "coshD", "hyperbolic cosine function working with degrees")); - functions.insert(tanhD_F, translate("VTranslateVars", "tanhD", "hyperbolic tangens function working with degrees")); - functions.insert(asinhD_F, translate("VTranslateVars", "asinhD", "hyperbolic arcus sine function working with degrees")); - functions.insert(acoshD_F, translate("VTranslateVars", "acoshD", "hyperbolic arcus cosine function working with degrees")); - functions.insert(atanhD_F, translate("VTranslateVars", "atanhD", "hyperbolic arcur tangens function working with degrees")); functions.insert(log2_F, translate("VTranslateVars", "log2", "logarithm to the base 2")); functions.insert(log10_F, translate("VTranslateVars", "log10", "logarithm to the base 10")); functions.insert(log_F, translate("VTranslateVars", "log", "logarithm to the base 10"));