Resolved issue #300. How to find even odd number.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-05-14 19:19:23 +03:00
parent d200548661
commit a869874429
5 changed files with 23 additions and 3 deletions

View File

@ -1516,6 +1516,8 @@ void VApplication::InitFunctions()
functions.insert(max_F, QmuTranslation::translate("Functions", "max", "max of all arguments"));
functions.insert(sum_F, QmuTranslation::translate("Functions", "sum", "sum of all arguments"));
functions.insert(avg_F, QmuTranslation::translate("Functions", "avg", "mean value of all arguments"));
functions.insert(fmod_F, QmuTranslation::translate("Functions", "fmod",
"Returns the floating-point remainder of numer/denom (rounded towards zero)"));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -213,12 +213,13 @@ const QString min_F = QStringLiteral("min");
const QString max_F = QStringLiteral("max");
const QString sum_F = QStringLiteral("sum");
const QString avg_F = QStringLiteral("avg");
const QString fmod_F = QStringLiteral("fmod");
const QStringList builInFunctions = QStringList() << sin_F << cos_F << tan_F << asin_F << acos_F << atan_F
<< sinh_F << cosh_F << tanh_F << asinh_F << acosh_F << atanh_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;
<< avg_F << fmod_F;
// Postfix operators
const QString cm_Oprt = QStringLiteral("cm");

View File

@ -306,6 +306,7 @@ extern const QString min_F;
extern const QString max_F;
extern const QString sum_F;
extern const QString avg_F;
extern const QString fmod_F;
extern const QStringList builInFunctions;

View File

@ -36,32 +36,38 @@ using namespace std;
*/
namespace qmu
{
//---------------------------------------------------------------------------------------------------------------------
// Trigonometric function
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::ACosh(qreal v)
{
return log(v + qSqrt(v * v - 1));
}
//---------------------------------------------------------------------------------------------------------------------
qreal QmuParser::ATanh(qreal v)
{
return (0.5 * log((1 + v) / (1 - v)));
@ -69,6 +75,7 @@ qreal QmuParser::ATanh(qreal v)
//---------------------------------------------------------------------------------------------------------------------
// Logarithm functions
//---------------------------------------------------------------------------------------------------------------------
// Logarithm base 2
qreal QmuParser::Log2(qreal v)
{
@ -81,6 +88,7 @@ qreal QmuParser::Log2(qreal v)
return log(v)/log(2.0);
}
//---------------------------------------------------------------------------------------------------------------------
// Logarithm base 10
qreal QmuParser::Log10(qreal v)
{
@ -100,16 +108,24 @@ qreal QmuParser::Abs(qreal v)
return qAbs(v);
}
//---------------------------------------------------------------------------------------------------------------------
qreal QmuParser::Rint(qreal v)
{
return qFloor(v + 0.5);
}
//---------------------------------------------------------------------------------------------------------------------
qreal QmuParser::Sign(qreal v)
{
return ((v<0) ? -1 : (v>0) ? 1 : 0);
}
//---------------------------------------------------------------------------------------------------------------------
qreal QmuParser::FMod(qreal number, qreal denom)
{
return fmod(number, denom);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Callback for adding multiple values.
@ -284,6 +300,7 @@ void QmuParser::InitFun()
DefineFun("sign", Sign);
DefineFun("rint", Rint);
DefineFun("abs", Abs);
DefineFun("fmod", FMod);
// Functions with variable number of arguments
DefineFun("sum", Sum);
DefineFun("avg", Avg);

View File

@ -54,8 +54,6 @@ namespace qmu
qreal Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon = 0) const;
protected:
static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const std::locale &s_locale);
// Trigonometric functions
static qreal Tan2(qreal, qreal);
// hyperbolic functions
static qreal Sinh(qreal);
static qreal Cosh(qreal);
@ -71,6 +69,7 @@ namespace qmu
static qreal Abs(qreal);
static qreal Rint(qreal);
static qreal Sign(qreal);
static qreal FMod(qreal, qreal);
// Prefix operators
// !!! Unary Minus is a MUST if you want to use negative signs !!!
static qreal UnaryMinus(qreal v);