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
This commit is contained in:
Roman Telezhynskyi 2017-04-14 18:42:49 +03:00
parent a7b721941a
commit 73c035ecc9
5 changed files with 21 additions and 88 deletions

View File

@ -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);

View File

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

View File

@ -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;

View File

@ -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;

View File

@ -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"));