24 #include <QCoreApplication>
25 #include <QStaticStringData>
26 #include <QStringData>
27 #include <QStringDataPtr>
34 #include "../vmisc/vmath.h"
50 return qDegreesToRadians(deg);
56 return qRadiansToDegrees(rad);
68 return log(v + qSqrt(v * v + 1));
80 return log(v + qSqrt(v * v - 1));
92 return (0.5 * log((1 + v) / (1 - v)));
98 return qSin(qDegreesToRadians(v));
104 return qRadiansToDegrees(qAsin(v));
110 return qCos(qDegreesToRadians(v));
116 return qRadiansToDegrees(qAcos(v));
122 return qTan(qDegreesToRadians(v));
128 return qRadiansToDegrees(qAtan(v));
138 #ifdef MUP_MATH_EXCEPTIONS
144 return log(v)/log(2.0);
151 #ifdef MUP_MATH_EXCEPTIONS
170 return qFloor(v + 0.5);
176 return ((v<0) ? -1 : (v>0) ? 1 : 0);
182 return fmod(number, denom);
196 "parser error message"));
199 for (
int i=0; i<a_iArgc; ++i)
217 "parser error message"));
220 for (
int i=0; i<a_iArgc; ++i)
224 return fRes/
static_cast<qreal
>(a_iArgc);
238 "parser error message"));
240 qreal fRes=a_afArg[0];
241 for (
int i=0; i<a_iArgc; ++i)
243 fRes = qMin(fRes, a_afArg[i]);
259 "parser error message"));
261 qreal fRes=a_afArg[0];
262 for (
int i=0; i<a_iArgc; ++i)
264 fRes = qMax(fRes, a_afArg[i]);
277 int QmuParser::IsVal(
const QString &a_szExpr,
int *a_iPos, qreal *a_fVal,
const QLocale &locale,
const QChar &decimal,
278 const QChar &thousand)
282 const int pos =
ReadVal(a_szExpr, fVal, locale, decimal, thousand);
320 DefineNameChars( QStringLiteral(
"0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") );
321 DefineOprtChars( QStringLiteral(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-*^/?<>=#!$%&|~'_{}") );
449 fEpsilon(a_fEpsilon);
453 if (qFuzzyIsNull(fEpsilon))
455 fEpsilon = qFuzzyIsNull(a_fPos) ?
static_cast<qreal
>(1e-10) :
static_cast<qreal
>(1e-7) * a_fPos;
458 *a_Var = a_fPos+2 * fEpsilon; f[0] =
Eval();
459 *a_Var = a_fPos+1 * fEpsilon; f[1] =
Eval();
460 *a_Var = a_fPos-1 * fEpsilon; f[2] =
Eval();
461 *a_Var = a_fPos-2 * fEpsilon; f[3] =
Eval();
464 fRes = (-f[0] + 8*f[1] - 8*f[2] + f[3]) / (12*fEpsilon);
Mathematical expressions parser (base parser engine).
void DefineOprtChars(const QString &a_szCharset)
Define the set of valid characters to be used in names of binary operators and postfix operators.
void DefineFun(const QString &a_strName, T a_pFun, bool a_bAllowOpt=true)
Define a parser function without arguments.
void DefineInfixOprtChars(const QString &a_szCharset)
Define the set of valid characters to be used in names of infix operators.
QLocale m_locale
The locale used by the parser.
qreal Eval() const
Calculate the result.
void AddValIdent(identfun_type a_pCallback)
Add a value parsing function.
void DefineConst(const QString &a_sName, qreal a_fVal)
Add a user defined constant.
void DefineInfixOprt(const QString &a_sName, fun_type1 a_pFun, int a_iPrec=prINFIX, bool a_bAllowOpt=true)
Add a user defined operator.
void DefineNameChars(const QString &a_szCharset)
Define the set of valid characters to be used in names of functions, variables, constants.
Error class of the parser.
virtual void InitOprt() Q_DECL_OVERRIDE
Initialize operators.
static qreal Min(const qreal *, int)
Callback for determining the minimum value out of a vector.
virtual void InitFun() Q_DECL_OVERRIDE
Initialize the default functions.
static qreal RadianToDegree(qreal)
static qreal Sum(const qreal *, int)
Callback for adding multiple values.
static qreal ACosD(qreal)
static qreal UnaryMinus(qreal v)
Callback for the unary minus operator.
virtual void InitConst() Q_DECL_OVERRIDE
Initialize constants.
static qreal ACosh(qreal)
static qreal ATanh(qreal)
static qreal DegreeToRadian(qreal)
static qreal ATanD(qreal)
static qreal FMod(qreal, qreal)
static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, const QChar &decimal, const QChar &thousand)
Default value recognition callback.
static qreal ASinh(qreal)
static qreal Avg(const qreal *, int)
Callback for averaging multiple values.
virtual void OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) Q_DECL_OVERRIDE
qreal Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon=0) const
Numerically differentiate with regard to a variable.
static qreal ASinD(qreal)
virtual void InitCharSets() Q_DECL_OVERRIDE
Define the character sets.
static qreal Max(const qreal *, int)
Callback for determining the maximum value out of a vector.
static qreal Log10(qreal)
Namespace for mathematical applications.
@ ecDOMAIN_ERROR
catch division by zero, sqrt(-1), log(0) (currently unused)
int ReadVal(const QString &formula, qreal &val, const QLocale &locale, const QChar &decimal, const QChar &thousand)
Definition of the standard floating point parser.
This file contains standard definitions used by the parser.
This file defines the error class used by the parser.
#define translate(context, source)