diff options
author | Shawn Rutledge <[email protected]> | 2018-02-28 18:52:00 +0100 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2018-05-15 11:46:50 +0000 |
commit | 925b18d0cbb444d5a05fbc5689463f2b0ec11927 (patch) | |
tree | 774cb69b395cc3d8c597d64a9ec3536bd9bbbca9 /src/qml/jsruntime/qv4mathobject.cpp | |
parent | f8a415e3eb0b5cc175417ce4782b071c154846e0 (diff) |
v4: add the remaining Math.log functions
We only had natural log, now we have base 2 and base 10 and log1p.
Change-Id: I26e3a50a27821671cf2fb4ed3905a357c23bbecc
Reviewed-by: Lars Knoll <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4mathobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4mathobject.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 0c18d908de..43459211f6 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -78,6 +78,9 @@ void Heap::MathObject::init() m->defineDefaultProperty(QStringLiteral("exp"), QV4::MathObject::method_exp, 1); m->defineDefaultProperty(QStringLiteral("floor"), QV4::MathObject::method_floor, 1); m->defineDefaultProperty(QStringLiteral("log"), QV4::MathObject::method_log, 1); + m->defineDefaultProperty(QStringLiteral("log10"), QV4::MathObject::method_log10, 1); + m->defineDefaultProperty(QStringLiteral("log1p"), QV4::MathObject::method_log1p, 1); + m->defineDefaultProperty(QStringLiteral("log2"), QV4::MathObject::method_log2, 1); m->defineDefaultProperty(QStringLiteral("max"), QV4::MathObject::method_max, 2); m->defineDefaultProperty(QStringLiteral("min"), QV4::MathObject::method_min, 2); m->defineDefaultProperty(QStringLiteral("pow"), QV4::MathObject::method_pow, 2); @@ -201,6 +204,38 @@ ReturnedValue MathObject::method_log(const FunctionObject *, const Value *, cons RETURN_RESULT(Encode(std::log(v))); } +ReturnedValue MathObject::method_log10(const FunctionObject *, const Value *, const Value *argv, int argc) +{ + double v = argc ? argv[0].toNumber() : qt_qnan(); + if (v < 0) + RETURN_RESULT(Encode(qt_qnan())); + else + RETURN_RESULT(Encode(std::log10(v))); +} + +ReturnedValue MathObject::method_log1p(const FunctionObject *, const Value *, const Value *argv, int argc) +{ +#if !defined(__ANDROID__) + using std::log1p; +#endif + double v = argc ? argv[0].toNumber() : qt_qnan(); + if (v < -1) + RETURN_RESULT(Encode(qt_qnan())); + else + RETURN_RESULT(Encode(log1p(v))); +} + +ReturnedValue MathObject::method_log2(const FunctionObject *, const Value *, const Value *argv, int argc) +{ + double v = argc ? argv[0].toNumber() : qt_qnan(); + if (v < 0) { + RETURN_RESULT(Encode(qt_qnan())); + } else { + // Android ndk r10e doesn't have std::log2, so fall back. + RETURN_RESULT(Encode(std::log(v) / std::log(2.0))); + } +} + ReturnedValue MathObject::method_max(const FunctionObject *, const Value *, const Value *argv, int argc) { double mx = -qt_inf(); |