| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4mathobject.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qv4mathobject_p.h" | - | ||||||||||||||||||||||||
| 41 | #include "qv4objectproto_p.h" | - | ||||||||||||||||||||||||
| 42 | #include "qv4symbol_p.h" | - | ||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | #include <QtCore/qdatetime.h> | - | ||||||||||||||||||||||||
| 45 | #include <QtCore/qmath.h> | - | ||||||||||||||||||||||||
| 46 | #include <QtCore/qrandom.h> | - | ||||||||||||||||||||||||
| 47 | #include <QtCore/private/qnumeric_p.h> | - | ||||||||||||||||||||||||
| 48 | #include <QtCore/qthreadstorage.h> | - | ||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||
| 50 | #include <math.h> | - | ||||||||||||||||||||||||
| 51 | #include <cmath> | - | ||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | using namespace QV4; | - | ||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | DEFINE_OBJECT_VTABLE(MathObject); | - | ||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | void Heap::MathObject::init() | - | ||||||||||||||||||||||||
| 58 | { | - | ||||||||||||||||||||||||
| 59 | Object::init(); | - | ||||||||||||||||||||||||
| 60 | Scope scope(internalClass->engine); | - | ||||||||||||||||||||||||
| 61 | ScopedObject m(scope, this); | - | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | m->defineReadonlyProperty(QStringLiteral("E"), Primitive::fromDouble(M_E)); executed 98149 times by 153 tests: return qstring_literal_temp;Executed by:
| 98149 | ||||||||||||||||||||||||
| 64 | m->defineReadonlyProperty(QStringLiteral("LN2"), Primitive::fromDouble(M_LN2)); executed 98474 times by 153 tests: return qstring_literal_temp;Executed by:
| 98474 | ||||||||||||||||||||||||
| 65 | m->defineReadonlyProperty(QStringLiteral("LN10"), Primitive::fromDouble(M_LN10)); executed 98680 times by 153 tests: return qstring_literal_temp;Executed by:
| 98680 | ||||||||||||||||||||||||
| 66 | m->defineReadonlyProperty(QStringLiteral("LOG2E"), Primitive::fromDouble(M_LOG2E)); executed 98732 times by 153 tests: return qstring_literal_temp;Executed by:
| 98732 | ||||||||||||||||||||||||
| 67 | m->defineReadonlyProperty(QStringLiteral("LOG10E"), Primitive::fromDouble(M_LOG10E)); executed 98637 times by 153 tests: return qstring_literal_temp;Executed by:
| 98637 | ||||||||||||||||||||||||
| 68 | m->defineReadonlyProperty(QStringLiteral("PI"), Primitive::fromDouble(M_PI)); executed 98850 times by 153 tests: return qstring_literal_temp;Executed by:
| 98850 | ||||||||||||||||||||||||
| 69 | m->defineReadonlyProperty(QStringLiteral("SQRT1_2"), Primitive::fromDouble(M_SQRT1_2)); executed 98491 times by 153 tests: return qstring_literal_temp;Executed by:
| 98491 | ||||||||||||||||||||||||
| 70 | m->defineReadonlyProperty(QStringLiteral("SQRT2"), Primitive::fromDouble(M_SQRT2)); executed 98453 times by 153 tests: return qstring_literal_temp;Executed by:
| 98453 | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | m->defineDefaultProperty(QStringLiteral("abs"), QV4::MathObject::method_abs, 1); executed 98501 times by 153 tests: return qstring_literal_temp;Executed by:
| 98501 | ||||||||||||||||||||||||
| 73 | m->defineDefaultProperty(QStringLiteral("acos"), QV4::MathObject::method_acos, 1); executed 98595 times by 153 tests: return qstring_literal_temp;Executed by:
| 98595 | ||||||||||||||||||||||||
| 74 | m->defineDefaultProperty(QStringLiteral("acosh"), QV4::MathObject::method_acosh, 1); executed 98691 times by 153 tests: return qstring_literal_temp;Executed by:
| 98691 | ||||||||||||||||||||||||
| 75 | m->defineDefaultProperty(QStringLiteral("asin"), QV4::MathObject::method_asin, 1); executed 98532 times by 153 tests: return qstring_literal_temp;Executed by:
| 98532 | ||||||||||||||||||||||||
| 76 | m->defineDefaultProperty(QStringLiteral("asinh"), QV4::MathObject::method_asinh, 1); executed 98458 times by 153 tests: return qstring_literal_temp;Executed by:
| 98458 | ||||||||||||||||||||||||
| 77 | m->defineDefaultProperty(QStringLiteral("atan"), QV4::MathObject::method_atan, 1); executed 98658 times by 153 tests: return qstring_literal_temp;Executed by:
| 98658 | ||||||||||||||||||||||||
| 78 | m->defineDefaultProperty(QStringLiteral("atanh"), QV4::MathObject::method_atanh, 1); executed 98659 times by 153 tests: return qstring_literal_temp;Executed by:
| 98659 | ||||||||||||||||||||||||
| 79 | m->defineDefaultProperty(QStringLiteral("atan2"), QV4::MathObject::method_atan2, 2); executed 98669 times by 153 tests: return qstring_literal_temp;Executed by:
| 98669 | ||||||||||||||||||||||||
| 80 | m->defineDefaultProperty(QStringLiteral("cbrt"), QV4::MathObject::method_cbrt, 1); executed 98658 times by 153 tests: return qstring_literal_temp;Executed by:
| 98658 | ||||||||||||||||||||||||
| 81 | m->defineDefaultProperty(QStringLiteral("ceil"), QV4::MathObject::method_ceil, 1); executed 98548 times by 153 tests: return qstring_literal_temp;Executed by:
| 98548 | ||||||||||||||||||||||||
| 82 | m->defineDefaultProperty(QStringLiteral("clz32"), QV4::MathObject::method_clz32, 1); executed 98770 times by 153 tests: return qstring_literal_temp;Executed by:
| 98770 | ||||||||||||||||||||||||
| 83 | m->defineDefaultProperty(QStringLiteral("cos"), QV4::MathObject::method_cos, 1); executed 99124 times by 153 tests: return qstring_literal_temp;Executed by:
| 99124 | ||||||||||||||||||||||||
| 84 | m->defineDefaultProperty(QStringLiteral("cosh"), QV4::MathObject::method_cosh, 1); executed 98448 times by 153 tests: return qstring_literal_temp;Executed by:
| 98448 | ||||||||||||||||||||||||
| 85 | m->defineDefaultProperty(QStringLiteral("exp"), QV4::MathObject::method_exp, 1); executed 98579 times by 153 tests: return qstring_literal_temp;Executed by:
| 98579 | ||||||||||||||||||||||||
| 86 | m->defineDefaultProperty(QStringLiteral("expm1"), QV4::MathObject::method_expm1, 1); executed 98550 times by 153 tests: return qstring_literal_temp;Executed by:
| 98550 | ||||||||||||||||||||||||
| 87 | m->defineDefaultProperty(QStringLiteral("floor"), QV4::MathObject::method_floor, 1); executed 98589 times by 153 tests: return qstring_literal_temp;Executed by:
| 98589 | ||||||||||||||||||||||||
| 88 | m->defineDefaultProperty(QStringLiteral("fround"), QV4::MathObject::method_fround, 1); executed 98522 times by 153 tests: return qstring_literal_temp;Executed by:
| 98522 | ||||||||||||||||||||||||
| 89 | m->defineDefaultProperty(QStringLiteral("hypot"), QV4::MathObject::method_hypot, 2); executed 98725 times by 153 tests: return qstring_literal_temp;Executed by:
| 98725 | ||||||||||||||||||||||||
| 90 | m->defineDefaultProperty(QStringLiteral("imul"), QV4::MathObject::method_imul, 2); executed 98735 times by 153 tests: return qstring_literal_temp;Executed by:
| 98735 | ||||||||||||||||||||||||
| 91 | m->defineDefaultProperty(QStringLiteral("log"), QV4::MathObject::method_log, 1); executed 99012 times by 153 tests: return qstring_literal_temp;Executed by:
| 99012 | ||||||||||||||||||||||||
| 92 | m->defineDefaultProperty(QStringLiteral("log10"), QV4::MathObject::method_log10, 1); executed 98562 times by 153 tests: return qstring_literal_temp;Executed by:
| 98562 | ||||||||||||||||||||||||
| 93 | m->defineDefaultProperty(QStringLiteral("log1p"), QV4::MathObject::method_log1p, 1); executed 98689 times by 153 tests: return qstring_literal_temp;Executed by:
| 98689 | ||||||||||||||||||||||||
| 94 | m->defineDefaultProperty(QStringLiteral("log2"), QV4::MathObject::method_log2, 1); executed 98732 times by 153 tests: return qstring_literal_temp;Executed by:
| 98732 | ||||||||||||||||||||||||
| 95 | m->defineDefaultProperty(QStringLiteral("max"), QV4::MathObject::method_max, 2); executed 98522 times by 153 tests: return qstring_literal_temp;Executed by:
| 98522 | ||||||||||||||||||||||||
| 96 | m->defineDefaultProperty(QStringLiteral("min"), QV4::MathObject::method_min, 2); executed 99033 times by 153 tests: return qstring_literal_temp;Executed by:
| 99033 | ||||||||||||||||||||||||
| 97 | m->defineDefaultProperty(QStringLiteral("pow"), QV4::MathObject::method_pow, 2); executed 98700 times by 153 tests: return qstring_literal_temp;Executed by:
| 98700 | ||||||||||||||||||||||||
| 98 | m->defineDefaultProperty(QStringLiteral("random"), QV4::MathObject::method_random, 0); executed 98598 times by 153 tests: return qstring_literal_temp;Executed by:
| 98598 | ||||||||||||||||||||||||
| 99 | m->defineDefaultProperty(QStringLiteral("round"), QV4::MathObject::method_round, 1); executed 98720 times by 153 tests: return qstring_literal_temp;Executed by:
| 98720 | ||||||||||||||||||||||||
| 100 | m->defineDefaultProperty(QStringLiteral("sign"), QV4::MathObject::method_sign, 1); executed 98170 times by 153 tests: return qstring_literal_temp;Executed by:
| 98170 | ||||||||||||||||||||||||
| 101 | m->defineDefaultProperty(QStringLiteral("sin"), QV4::MathObject::method_sin, 1); executed 99100 times by 153 tests: return qstring_literal_temp;Executed by:
| 99100 | ||||||||||||||||||||||||
| 102 | m->defineDefaultProperty(QStringLiteral("sinh"), QV4::MathObject::method_sinh, 1); executed 98951 times by 153 tests: return qstring_literal_temp;Executed by:
| 98951 | ||||||||||||||||||||||||
| 103 | m->defineDefaultProperty(QStringLiteral("sqrt"), QV4::MathObject::method_sqrt, 1); executed 98806 times by 153 tests: return qstring_literal_temp;Executed by:
| 98806 | ||||||||||||||||||||||||
| 104 | m->defineDefaultProperty(QStringLiteral("tan"), QV4::MathObject::method_tan, 1); executed 98808 times by 153 tests: return qstring_literal_temp;Executed by:
| 98808 | ||||||||||||||||||||||||
| 105 | m->defineDefaultProperty(QStringLiteral("tanh"), QV4::MathObject::method_tanh, 1); executed 98858 times by 153 tests: return qstring_literal_temp;Executed by:
| 98858 | ||||||||||||||||||||||||
| 106 | m->defineDefaultProperty(QStringLiteral("trunc"), QV4::MathObject::method_trunc, 1); executed 98857 times by 153 tests: return qstring_literal_temp;Executed by:
| 98857 | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | ScopedString name(scope, scope.engine->newString(QStringLiteral("Math"))); executed 98971 times by 153 tests: return qstring_literal_temp;Executed by:
| 98971 | ||||||||||||||||||||||||
| 109 | m->defineReadonlyConfigurableProperty(scope.engine->symbol_toStringTag(), name); | - | ||||||||||||||||||||||||
| 110 | } executed 99041 times by 153 tests: end of blockExecuted by:
| 99041 | ||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||
| 112 | static Q_ALWAYS_INLINE double copySign(double x, double y) | - | ||||||||||||||||||||||||
| 113 | { | - | ||||||||||||||||||||||||
| 114 | return ::copysign(x, y); executed 8824 times by 3 tests: return ::copysign(x, y);Executed by:
| 8824 | ||||||||||||||||||||||||
| 115 | } | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | ReturnedValue MathObject::method_abs(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 118 | { | - | ||||||||||||||||||||||||
| 119 | if (!argc)
| 0-146 | ||||||||||||||||||||||||
| 120 | RETURN_RESULT(Encode(qt_qnan())); never executed: return QV4::Encode(Encode(qt_qnan())); | 0 | ||||||||||||||||||||||||
| 121 | - | |||||||||||||||||||||||||
| 122 | if (argv[0].isInteger()) {
| 24-122 | ||||||||||||||||||||||||
| 123 | int i = argv[0].integerValue(); | - | ||||||||||||||||||||||||
| 124 | RETURN_RESULT(Encode(i < 0 ? - i : i)); executed 24 times by 2 tests: return QV4::Encode(Encode(i < 0 ? - i : i));Executed by:
| 24 | ||||||||||||||||||||||||
| 125 | } | - | ||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||
| 127 | double v = argv[0].toNumber(); | - | ||||||||||||||||||||||||
| 128 | if (v == 0) // 0 | -0
| 20-102 | ||||||||||||||||||||||||
| 129 | RETURN_RESULT(Encode(0)); executed 20 times by 2 tests: return QV4::Encode(Encode(0));Executed by:
| 20 | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | RETURN_RESULT(Encode(v < 0 ? -v : v)); executed 102 times by 4 tests: return QV4::Encode(Encode(v < 0 ? -v : v));Executed by:
| 102 | ||||||||||||||||||||||||
| 132 | } | - | ||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||
| 134 | ReturnedValue MathObject::method_acos(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 135 | { | - | ||||||||||||||||||||||||
| 136 | double v = argc ? argv[0].toNumber() : 2;
| 0-31 | ||||||||||||||||||||||||
| 137 | if (v > 1)
| 12-20 | ||||||||||||||||||||||||
| 138 | RETURN_RESULT(Encode(qt_qnan())); executed 12 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 12 | ||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | RETURN_RESULT(Encode(std::acos(v))); executed 20 times by 1 test: return QV4::Encode(Encode(std::acos(v)));Executed by:
| 20 | ||||||||||||||||||||||||
| 141 | } | - | ||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||
| 143 | ReturnedValue MathObject::method_acosh(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 144 | { | - | ||||||||||||||||||||||||
| 145 | double v = argc ? argv[0].toNumber() : 2;
| 0-28 | ||||||||||||||||||||||||
| 146 | if (v < 1)
| 12-16 | ||||||||||||||||||||||||
| 147 | RETURN_RESULT(Encode(qt_qnan())); executed 16 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 16 | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | #ifdef Q_OS_ANDROID // incomplete std :-( | - | ||||||||||||||||||||||||
| 150 | RETURN_RESULT(Encode(std::log(v +std::sqrt(v + 1) * std::sqrt(v - 1)))); | - | ||||||||||||||||||||||||
| 151 | #else | - | ||||||||||||||||||||||||
| 152 | RETURN_RESULT(Encode(std::acosh(v))); executed 12 times by 1 test: return QV4::Encode(Encode(std::acosh(v)));Executed by:
| 12 | ||||||||||||||||||||||||
| 153 | #endif | - | ||||||||||||||||||||||||
| 154 | } | - | ||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | ReturnedValue MathObject::method_asin(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 157 | { | - | ||||||||||||||||||||||||
| 158 | double v = argc ? argv[0].toNumber() : 2;
| 0-36 | ||||||||||||||||||||||||
| 159 | if (v > 1)
| 12-24 | ||||||||||||||||||||||||
| 160 | RETURN_RESULT(Encode(qt_qnan())); executed 12 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 12 | ||||||||||||||||||||||||
| 161 | else | - | ||||||||||||||||||||||||
| 162 | RETURN_RESULT(Encode(std::asin(v))); executed 24 times by 1 test: return QV4::Encode(Encode(std::asin(v)));Executed by:
| 24 | ||||||||||||||||||||||||
| 163 | } | - | ||||||||||||||||||||||||
| 164 | - | |||||||||||||||||||||||||
| 165 | ReturnedValue MathObject::method_asinh(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 166 | { | - | ||||||||||||||||||||||||
| 167 | double v = argc ? argv[0].toNumber() : 2;
| 0-20 | ||||||||||||||||||||||||
| 168 | if (v == 0.0)
| 8-12 | ||||||||||||||||||||||||
| 169 | RETURN_RESULT(Encode(v)); executed 8 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 8 | ||||||||||||||||||||||||
| 170 | - | |||||||||||||||||||||||||
| 171 | #ifdef Q_OS_ANDROID // incomplete std :-( | - | ||||||||||||||||||||||||
| 172 | RETURN_RESULT(Encode(std::log(v +std::sqrt(1 + v * v)))); | - | ||||||||||||||||||||||||
| 173 | #else | - | ||||||||||||||||||||||||
| 174 | RETURN_RESULT(Encode(std::asinh(v))); executed 12 times by 1 test: return QV4::Encode(Encode(std::asinh(v)));Executed by:
| 12 | ||||||||||||||||||||||||
| 175 | #endif | - | ||||||||||||||||||||||||
| 176 | } | - | ||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||
| 178 | ReturnedValue MathObject::method_atan(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 179 | { | - | ||||||||||||||||||||||||
| 180 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-12 | ||||||||||||||||||||||||
| 181 | if (v == 0.0)
| 4-8 | ||||||||||||||||||||||||
| 182 | RETURN_RESULT(Encode(v)); executed 8 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 8 | ||||||||||||||||||||||||
| 183 | else | - | ||||||||||||||||||||||||
| 184 | RETURN_RESULT(Encode(std::atan(v))); executed 4 times by 1 test: return QV4::Encode(Encode(std::atan(v)));Executed by:
| 4 | ||||||||||||||||||||||||
| 185 | } | - | ||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | ReturnedValue MathObject::method_atanh(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 188 | { | - | ||||||||||||||||||||||||
| 189 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-44 | ||||||||||||||||||||||||
| 190 | if (v == 0.0)
| 8-36 | ||||||||||||||||||||||||
| 191 | RETURN_RESULT(Encode(v)); executed 8 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 8 | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | #ifdef Q_OS_ANDROID // incomplete std :-( | - | ||||||||||||||||||||||||
| 194 | if (-1 < v && v < 1) | - | ||||||||||||||||||||||||
| 195 | RETURN_RESULT(Encode(0.5 * (std::log(v + 1) - std::log(v - 1)))); | - | ||||||||||||||||||||||||
| 196 | - | |||||||||||||||||||||||||
| 197 | if (v > 1 || v < -1) | - | ||||||||||||||||||||||||
| 198 | RETURN_RESULT(Encode(qt_qnan())); | - | ||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||
| 200 | RETURN_RESULT(Encode(copySign(qt_inf(), v))); | - | ||||||||||||||||||||||||
| 201 | #else | - | ||||||||||||||||||||||||
| 202 | RETURN_RESULT(Encode(std::atanh(v))); executed 36 times by 1 test: return QV4::Encode(Encode(std::atanh(v)));Executed by:
| 36 | ||||||||||||||||||||||||
| 203 | #endif | - | ||||||||||||||||||||||||
| 204 | } | - | ||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||
| 206 | ReturnedValue MathObject::method_atan2(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 207 | { | - | ||||||||||||||||||||||||
| 208 | double v1 = argc ? argv[0].toNumber() : qt_qnan();
| 0-112 | ||||||||||||||||||||||||
| 209 | double v2 = argc > 1 ? argv[1].toNumber() : qt_qnan();
| 0-112 | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | if ((v1 < 0) && qt_is_finite(v1) && qt_is_inf(v2) && (copySign(1.0, v2) == 1.0))
| 0-92 | ||||||||||||||||||||||||
| 212 | RETURN_RESULT(Encode(copySign(0, -1.0))); executed 12 times by 1 test: return QV4::Encode(Encode(copySign(0, -1.0)));Executed by:
| 12 | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | if ((v1 == 0.0) && (v2 == 0.0)) {
| 8-60 | ||||||||||||||||||||||||
| 215 | if ((copySign(1.0, v1) == 1.0) && (copySign(1.0, v2) == -1.0)) {
| 0-4 | ||||||||||||||||||||||||
| 216 | RETURN_RESULT(Encode(M_PI)); never executed: return QV4::Encode(Encode( 3.14159265358979323846 )); | 0 | ||||||||||||||||||||||||
| 217 | } else if ((copySign(1.0, v1) == -1.0) && (copySign(1.0, v2) == -1.0)) {
| 0-4 | ||||||||||||||||||||||||
| 218 | RETURN_RESULT(Encode(-M_PI)); never executed: return QV4::Encode(Encode(- 3.14159265358979323846 )); | 0 | ||||||||||||||||||||||||
| 219 | } | - | ||||||||||||||||||||||||
| 220 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 221 | RETURN_RESULT(Encode(std::atan2(v1, v2))); executed 100 times by 1 test: return QV4::Encode(Encode(std::atan2(v1, v2)));Executed by:
| 100 | ||||||||||||||||||||||||
| 222 | } | - | ||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | ReturnedValue MathObject::method_cbrt(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 225 | { | - | ||||||||||||||||||||||||
| 226 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-20 | ||||||||||||||||||||||||
| 227 | #ifdef Q_OS_ANDROID // incomplete std :-( | - | ||||||||||||||||||||||||
| 228 | RETURN_RESULT(Encode(copySign(std::exp(std::log(std::abs(v)) / 3), v))); | - | ||||||||||||||||||||||||
| 229 | #else | - | ||||||||||||||||||||||||
| 230 | RETURN_RESULT(Encode(std::cbrt(v))); // cube root executed 20 times by 1 test: return QV4::Encode(Encode(std::cbrt(v)));Executed by:
| 20 | ||||||||||||||||||||||||
| 231 | #endif | - | ||||||||||||||||||||||||
| 232 | } | - | ||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||
| 234 | ReturnedValue MathObject::method_ceil(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 235 | { | - | ||||||||||||||||||||||||
| 236 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-16058 | ||||||||||||||||||||||||
| 237 | if (v < 0.0 && v > -1.0)
| 84-8036 | ||||||||||||||||||||||||
| 238 | RETURN_RESULT(Encode(copySign(0, -1.0))); executed 84 times by 1 test: return QV4::Encode(Encode(copySign(0, -1.0)));Executed by:
| 84 | ||||||||||||||||||||||||
| 239 | else | - | ||||||||||||||||||||||||
| 240 | RETURN_RESULT(Encode(std::ceil(v))); executed 15974 times by 2 tests: return QV4::Encode(Encode(std::ceil(v)));Executed by:
| 15974 | ||||||||||||||||||||||||
| 241 | } | - | ||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||
| 243 | ReturnedValue MathObject::method_clz32(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 244 | { | - | ||||||||||||||||||||||||
| 245 | quint32 v = argc ? argv[0].toUInt32() : 0;
| 0-100 | ||||||||||||||||||||||||
| 246 | RETURN_RESULT(Encode(qint32(qCountLeadingZeroBits(v)))); executed 100 times by 1 test: return QV4::Encode(Encode(qint32(qCountLeadingZeroBits(v))));Executed by:
| 100 | ||||||||||||||||||||||||
| 247 | } | - | ||||||||||||||||||||||||
| 248 | - | |||||||||||||||||||||||||
| 249 | ReturnedValue MathObject::method_cos(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 250 | { | - | ||||||||||||||||||||||||
| 251 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-450 | ||||||||||||||||||||||||
| 252 | RETURN_RESULT(Encode(std::cos(v))); executed 450 times by 2 tests: return QV4::Encode(Encode(std::cos(v)));Executed by:
| 450 | ||||||||||||||||||||||||
| 253 | } | - | ||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||
| 255 | ReturnedValue MathObject::method_cosh(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 256 | { | - | ||||||||||||||||||||||||
| 257 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-20 | ||||||||||||||||||||||||
| 258 | RETURN_RESULT(Encode(std::cosh(v))); executed 20 times by 1 test: return QV4::Encode(Encode(std::cosh(v)));Executed by:
| 20 | ||||||||||||||||||||||||
| 259 | } | - | ||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||
| 261 | ReturnedValue MathObject::method_exp(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 262 | { | - | ||||||||||||||||||||||||
| 263 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-20 | ||||||||||||||||||||||||
| 264 | if (qt_is_inf(v)) {
| 8-12 | ||||||||||||||||||||||||
| 265 | if (copySign(1.0, v) == -1.0)
| 4 | ||||||||||||||||||||||||
| 266 | RETURN_RESULT(Encode(0)); executed 4 times by 1 test: return QV4::Encode(Encode(0));Executed by:
| 4 | ||||||||||||||||||||||||
| 267 | else | - | ||||||||||||||||||||||||
| 268 | RETURN_RESULT(Encode(qt_inf())); executed 4 times by 1 test: return QV4::Encode(Encode(qt_inf()));Executed by:
| 4 | ||||||||||||||||||||||||
| 269 | } else { | - | ||||||||||||||||||||||||
| 270 | RETURN_RESULT(Encode(std::exp(v))); executed 12 times by 1 test: return QV4::Encode(Encode(std::exp(v)));Executed by:
| 12 | ||||||||||||||||||||||||
| 271 | } | - | ||||||||||||||||||||||||
| 272 | } | - | ||||||||||||||||||||||||
| 273 | - | |||||||||||||||||||||||||
| 274 | ReturnedValue MathObject::method_expm1(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 275 | { | - | ||||||||||||||||||||||||
| 276 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-20 | ||||||||||||||||||||||||
| 277 | if (std::isnan(v) || qIsNull(v)) {
| 4-16 | ||||||||||||||||||||||||
| 278 | RETURN_RESULT(Encode(v)); executed 12 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 12 | ||||||||||||||||||||||||
| 279 | } else if (qt_is_inf(v)) {
| 0-8 | ||||||||||||||||||||||||
| 280 | if (copySign(1.0, v) == -1.0)
| 4 | ||||||||||||||||||||||||
| 281 | RETURN_RESULT(Encode(-1.0)); executed 4 times by 1 test: return QV4::Encode(Encode(-1.0));Executed by:
| 4 | ||||||||||||||||||||||||
| 282 | else | - | ||||||||||||||||||||||||
| 283 | RETURN_RESULT(Encode(qt_inf())); executed 4 times by 1 test: return QV4::Encode(Encode(qt_inf()));Executed by:
| 4 | ||||||||||||||||||||||||
| 284 | } else { | - | ||||||||||||||||||||||||
| 285 | #ifdef Q_OS_ANDROID // incomplete std :-( | - | ||||||||||||||||||||||||
| 286 | RETURN_RESULT(Encode(std::exp(v) - 1)); | - | ||||||||||||||||||||||||
| 287 | #else | - | ||||||||||||||||||||||||
| 288 | RETURN_RESULT(Encode(std::expm1(v))); never executed: return QV4::Encode(Encode(std::expm1(v))); | 0 | ||||||||||||||||||||||||
| 289 | #endif | - | ||||||||||||||||||||||||
| 290 | } | - | ||||||||||||||||||||||||
| 291 | } | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | ReturnedValue MathObject::method_floor(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 294 | { | - | ||||||||||||||||||||||||
| 295 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-1007279 | ||||||||||||||||||||||||
| 296 | Value result = Primitive::fromDouble(std::floor(v)); | - | ||||||||||||||||||||||||
| 297 | result.isInt32(); | - | ||||||||||||||||||||||||
| 298 | RETURN_RESULT(result); executed 1007278 times by 4 tests: return QV4::Encode(result);Executed by:
| 1007278 | ||||||||||||||||||||||||
| 299 | } | - | ||||||||||||||||||||||||
| 300 | - | |||||||||||||||||||||||||
| 301 | ReturnedValue MathObject::method_fround(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 302 | { | - | ||||||||||||||||||||||||
| 303 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-40 | ||||||||||||||||||||||||
| 304 | if (std::isnan(v) || qt_is_inf(v) || qIsNull(v))
| 4-36 | ||||||||||||||||||||||||
| 305 | RETURN_RESULT(Encode(v)); executed 16 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 16 | ||||||||||||||||||||||||
| 306 | else // convert to 32-bit float using roundTiesToEven, then convert back to 64-bit double | - | ||||||||||||||||||||||||
| 307 | RETURN_RESULT(Encode(double(float(v)))); executed 24 times by 1 test: return QV4::Encode(Encode(double(float(v))));Executed by:
| 24 | ||||||||||||||||||||||||
| 308 | } | - | ||||||||||||||||||||||||
| 309 | - | |||||||||||||||||||||||||
| 310 | ReturnedValue MathObject::method_hypot(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 311 | { | - | ||||||||||||||||||||||||
| 312 | // ES6 Math.hypot(v1, ..., vn) -> sqrt(sum(vi**2)) but "should take care to | - | ||||||||||||||||||||||||
| 313 | // avoid the loss of precision from overflows and underflows" (as std::hypot does). | - | ||||||||||||||||||||||||
| 314 | double v = argc ? argv[0].toNumber() : 0;
| 4-36 | ||||||||||||||||||||||||
| 315 | // Spec mandates +0 on no args; and says nothing about what to do if toNumber() signals ... | - | ||||||||||||||||||||||||
| 316 | #ifdef Q_OS_ANDROID // incomplete std :-( | - | ||||||||||||||||||||||||
| 317 | bool big = qt_is_inf(v), bad = std::isnan(v); | - | ||||||||||||||||||||||||
| 318 | v *= v; | - | ||||||||||||||||||||||||
| 319 | for (int i = 1; !big && i < argc; i++) { | - | ||||||||||||||||||||||||
| 320 | double u = argv[i].toNumber(); | - | ||||||||||||||||||||||||
| 321 | if (qt_is_inf(u)) | - | ||||||||||||||||||||||||
| 322 | big = true; | - | ||||||||||||||||||||||||
| 323 | if (std::isnan(u)) | - | ||||||||||||||||||||||||
| 324 | bad = true; | - | ||||||||||||||||||||||||
| 325 | v += u * u; | - | ||||||||||||||||||||||||
| 326 | } | - | ||||||||||||||||||||||||
| 327 | if (big) | - | ||||||||||||||||||||||||
| 328 | RETURN_RESULT(Encode(qt_inf())); | - | ||||||||||||||||||||||||
| 329 | if (bad) | - | ||||||||||||||||||||||||
| 330 | RETURN_RESULT(Encode(qt_qnan())); | - | ||||||||||||||||||||||||
| 331 | // Should actually check for {und,ov}erflow, but too fiddly ! | - | ||||||||||||||||||||||||
| 332 | RETURN_RESULT(Primitive::fromDouble(sqrt(v))); | - | ||||||||||||||||||||||||
| 333 | #else | - | ||||||||||||||||||||||||
| 334 | for (int i = 1; i < argc; i++)
| 36-40 | ||||||||||||||||||||||||
| 335 | v = std::hypot(v, argv[i].toNumber()); executed 36 times by 1 test: v = std::hypot(v, argv[i].toNumber());Executed by:
| 36 | ||||||||||||||||||||||||
| 336 | #endif | - | ||||||||||||||||||||||||
| 337 | RETURN_RESULT(Primitive::fromDouble(v)); executed 40 times by 1 test: return QV4::Encode(Primitive::fromDouble(v));Executed by:
| 40 | ||||||||||||||||||||||||
| 338 | } | - | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | ReturnedValue MathObject::method_imul(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 341 | { | - | ||||||||||||||||||||||||
| 342 | quint32 a = argc ? argv[0].toUInt32() : 0;
| 0-136 | ||||||||||||||||||||||||
| 343 | quint32 b = argc > 0 ? argv[1].toUInt32() : 0;
| 0-136 | ||||||||||||||||||||||||
| 344 | qint32 product = a * b; | - | ||||||||||||||||||||||||
| 345 | RETURN_RESULT(Encode(product)); executed 136 times by 1 test: return QV4::Encode(Encode(product));Executed by:
| 136 | ||||||||||||||||||||||||
| 346 | } | - | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | ReturnedValue MathObject::method_log(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 349 | { | - | ||||||||||||||||||||||||
| 350 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-32 | ||||||||||||||||||||||||
| 351 | if (v < 0)
| 12-20 | ||||||||||||||||||||||||
| 352 | RETURN_RESULT(Encode(qt_qnan())); executed 12 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 12 | ||||||||||||||||||||||||
| 353 | else | - | ||||||||||||||||||||||||
| 354 | RETURN_RESULT(Encode(std::log(v))); executed 20 times by 1 test: return QV4::Encode(Encode(std::log(v)));Executed by:
| 20 | ||||||||||||||||||||||||
| 355 | } | - | ||||||||||||||||||||||||
| 356 | - | |||||||||||||||||||||||||
| 357 | ReturnedValue MathObject::method_log10(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 358 | { | - | ||||||||||||||||||||||||
| 359 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-48 | ||||||||||||||||||||||||
| 360 | if (v < 0)
| 8-40 | ||||||||||||||||||||||||
| 361 | RETURN_RESULT(Encode(qt_qnan())); executed 8 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 8 | ||||||||||||||||||||||||
| 362 | else | - | ||||||||||||||||||||||||
| 363 | RETURN_RESULT(Encode(std::log10(v))); executed 40 times by 1 test: return QV4::Encode(Encode(std::log10(v)));Executed by:
| 40 | ||||||||||||||||||||||||
| 364 | } | - | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | ReturnedValue MathObject::method_log1p(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 367 | { | - | ||||||||||||||||||||||||
| 368 | #if !defined(__ANDROID__) | - | ||||||||||||||||||||||||
| 369 | using std::log1p; | - | ||||||||||||||||||||||||
| 370 | #endif | - | ||||||||||||||||||||||||
| 371 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-32 | ||||||||||||||||||||||||
| 372 | if (v < -1)
| 12-20 | ||||||||||||||||||||||||
| 373 | RETURN_RESULT(Encode(qt_qnan())); executed 12 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 12 | ||||||||||||||||||||||||
| 374 | else | - | ||||||||||||||||||||||||
| 375 | RETURN_RESULT(Encode(log1p(v))); executed 20 times by 1 test: return QV4::Encode(Encode(log1p(v)));Executed by:
| 20 | ||||||||||||||||||||||||
| 376 | } | - | ||||||||||||||||||||||||
| 377 | - | |||||||||||||||||||||||||
| 378 | ReturnedValue MathObject::method_log2(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 379 | { | - | ||||||||||||||||||||||||
| 380 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-52 | ||||||||||||||||||||||||
| 381 | if (v < 0) {
| 12-40 | ||||||||||||||||||||||||
| 382 | RETURN_RESULT(Encode(qt_qnan())); executed 12 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 12 | ||||||||||||||||||||||||
| 383 | } else { | - | ||||||||||||||||||||||||
| 384 | #ifdef Q_OS_ANDROID // incomplete std :-( | - | ||||||||||||||||||||||||
| 385 | // Android ndk r10e doesn't have std::log2, so fall back. | - | ||||||||||||||||||||||||
| 386 | const double ln2 = std::log(2.0); | - | ||||||||||||||||||||||||
| 387 | RETURN_RESULT(Encode(std::log(v) / ln2)); | - | ||||||||||||||||||||||||
| 388 | #else | - | ||||||||||||||||||||||||
| 389 | RETURN_RESULT(Encode(std::log2(v))); executed 40 times by 1 test: return QV4::Encode(Encode(std::log2(v)));Executed by:
| 40 | ||||||||||||||||||||||||
| 390 | #endif | - | ||||||||||||||||||||||||
| 391 | } | - | ||||||||||||||||||||||||
| 392 | } | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | ReturnedValue MathObject::method_max(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 395 | { | - | ||||||||||||||||||||||||
| 396 | double mx = -qt_inf(); | - | ||||||||||||||||||||||||
| 397 | for (int i = 0, ei = argc; i < ei; ++i) {
| 5692-11956 | ||||||||||||||||||||||||
| 398 | double x = argv[i].toNumber(); | - | ||||||||||||||||||||||||
| 399 | if (x > mx || std::isnan(x))
| 828-9471 | ||||||||||||||||||||||||
| 400 | mx = x; executed 10299 times by 7 tests: mx = x;Executed by:
| 10299 | ||||||||||||||||||||||||
| 401 | } executed 11956 times by 7 tests: end of blockExecuted by:
| 11956 | ||||||||||||||||||||||||
| 402 | RETURN_RESULT(Encode(mx)); executed 5692 times by 7 tests: return QV4::Encode(Encode(mx));Executed by:
| 5692 | ||||||||||||||||||||||||
| 403 | } | - | ||||||||||||||||||||||||
| 404 | - | |||||||||||||||||||||||||
| 405 | ReturnedValue MathObject::method_min(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 406 | { | - | ||||||||||||||||||||||||
| 407 | double mx = qt_inf(); | - | ||||||||||||||||||||||||
| 408 | for (int i = 0, ei = argc; i < ei; ++i) {
| 2650-5876 | ||||||||||||||||||||||||
| 409 | double x = argv[i].toNumber(); | - | ||||||||||||||||||||||||
| 410 | if ((x == 0 && mx == x && copySign(1.0, x) == -1.0)
| 20-4744 | ||||||||||||||||||||||||
| 411 | || (x < mx) || std::isnan(x)) {
| 828-4039 | ||||||||||||||||||||||||
| 412 | mx = x; | - | ||||||||||||||||||||||||
| 413 | } executed 4887 times by 5 tests: end of blockExecuted by:
| 4887 | ||||||||||||||||||||||||
| 414 | } executed 5876 times by 5 tests: end of blockExecuted by:
| 5876 | ||||||||||||||||||||||||
| 415 | RETURN_RESULT(Encode(mx)); executed 2650 times by 5 tests: return QV4::Encode(Encode(mx));Executed by:
| 2650 | ||||||||||||||||||||||||
| 416 | } | - | ||||||||||||||||||||||||
| 417 | - | |||||||||||||||||||||||||
| 418 | ReturnedValue MathObject::method_pow(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 419 | { | - | ||||||||||||||||||||||||
| 420 | double x = argc > 0 ? argv[0].toNumber() : qt_qnan();
| 0-3015520 | ||||||||||||||||||||||||
| 421 | double y = argc > 1 ? argv[1].toNumber() : qt_qnan();
| 0-3015521 | ||||||||||||||||||||||||
| 422 | - | |||||||||||||||||||||||||
| 423 | if (std::isnan(y))
| 40-3015480 | ||||||||||||||||||||||||
| 424 | RETURN_RESULT(Encode(qt_qnan())); executed 40 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 40 | ||||||||||||||||||||||||
| 425 | - | |||||||||||||||||||||||||
| 426 | if (y == 0) {
| 753736-2261744 | ||||||||||||||||||||||||
| 427 | RETURN_RESULT(Encode(1)); executed 753736 times by 1 test: return QV4::Encode(Encode(1));Executed by:
| 753736 | ||||||||||||||||||||||||
| 428 | } else if (((x == 1) || (x == -1)) && std::isinf(y)) {
| 12-2261731 | ||||||||||||||||||||||||
| 429 | RETURN_RESULT(Encode(qt_qnan())); executed 16 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 16 | ||||||||||||||||||||||||
| 430 | } else if (((x == 0) && copySign(1.0, x) == 1.0) && (y < 0)) {
| 20-2261610 | ||||||||||||||||||||||||
| 431 | RETURN_RESULT(Encode(qInf())); executed 24 times by 1 test: return QV4::Encode(Encode(qInf()));Executed by:
| 24 | ||||||||||||||||||||||||
| 432 | } else if ((x == 0) && copySign(1.0, x) == -1.0) {
| 20-2261610 | ||||||||||||||||||||||||
| 433 | if (y < 0) {
| 36-40 | ||||||||||||||||||||||||
| 434 | if (std::fmod(-y, 2.0) == 1.0)
| 12-28 | ||||||||||||||||||||||||
| 435 | RETURN_RESULT(Encode(-qt_inf())); executed 12 times by 1 test: return QV4::Encode(Encode(-qt_inf()));Executed by:
| 12 | ||||||||||||||||||||||||
| 436 | else | - | ||||||||||||||||||||||||
| 437 | RETURN_RESULT(Encode(qt_inf())); executed 28 times by 1 test: return QV4::Encode(Encode(qt_inf()));Executed by:
| 28 | ||||||||||||||||||||||||
| 438 | } else if (y > 0) {
| 0-36 | ||||||||||||||||||||||||
| 439 | if (std::fmod(y, 2.0) == 1.0)
| 12-24 | ||||||||||||||||||||||||
| 440 | RETURN_RESULT(Encode(copySign(0, -1.0))); executed 12 times by 1 test: return QV4::Encode(Encode(copySign(0, -1.0)));Executed by:
| 12 | ||||||||||||||||||||||||
| 441 | else | - | ||||||||||||||||||||||||
| 442 | RETURN_RESULT(Encode(0)); executed 24 times by 1 test: return QV4::Encode(Encode(0));Executed by:
| 24 | ||||||||||||||||||||||||
| 443 | } | - | ||||||||||||||||||||||||
| 444 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | #ifdef Q_OS_AIX | - | ||||||||||||||||||||||||
| 447 | else if (qt_is_inf(x) && copySign(1.0, x) == -1.0) { | - | ||||||||||||||||||||||||
| 448 | if (y > 0) { | - | ||||||||||||||||||||||||
| 449 | if (std::fmod(y, 2.0) == 1.0) | - | ||||||||||||||||||||||||
| 450 | RETURN_RESULT(Encode(-qt_inf())); | - | ||||||||||||||||||||||||
| 451 | else | - | ||||||||||||||||||||||||
| 452 | RETURN_RESULT(Encode(qt_inf())); | - | ||||||||||||||||||||||||
| 453 | } else if (y < 0) { | - | ||||||||||||||||||||||||
| 454 | if (std::fmod(-y, 2.0) == 1.0) | - | ||||||||||||||||||||||||
| 455 | RETURN_RESULT(Encode(copySign(0, -1.0))); | - | ||||||||||||||||||||||||
| 456 | else | - | ||||||||||||||||||||||||
| 457 | RETURN_RESULT(Encode(0)); | - | ||||||||||||||||||||||||
| 458 | } | - | ||||||||||||||||||||||||
| 459 | } | - | ||||||||||||||||||||||||
| 460 | #endif | - | ||||||||||||||||||||||||
| 461 | else { | - | ||||||||||||||||||||||||
| 462 | RETURN_RESULT(Encode(std::pow(x, y))); executed 2261629 times by 1 test: return QV4::Encode(Encode(std::pow(x, y)));Executed by:
| 2261629 | ||||||||||||||||||||||||
| 463 | } | - | ||||||||||||||||||||||||
| 464 | // ### | - | ||||||||||||||||||||||||
| 465 | RETURN_RESULT(Encode(qt_qnan())); never executed: return QV4::Encode(Encode(qt_qnan())); | 0 | ||||||||||||||||||||||||
| 466 | } | - | ||||||||||||||||||||||||
| 467 | - | |||||||||||||||||||||||||
| 468 | ReturnedValue MathObject::method_random(const FunctionObject *, const Value *, const Value *, int) | - | ||||||||||||||||||||||||
| 469 | { | - | ||||||||||||||||||||||||
| 470 | RETURN_RESULT(Encode(QRandomGenerator::global()->generateDouble())); executed 7573 times by 6 tests: return QV4::Encode(Encode(QRandomGenerator::global()->generateDouble()));Executed by:
| 7573 | ||||||||||||||||||||||||
| 471 | } | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | ReturnedValue MathObject::method_round(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 474 | { | - | ||||||||||||||||||||||||
| 475 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-8408 | ||||||||||||||||||||||||
| 476 | if (std::isnan(v) || qt_is_inf(v) || qIsNull(v))
| 4-8404 | ||||||||||||||||||||||||
| 477 | RETURN_RESULT(Encode(v)); executed 32 times by 2 tests: return QV4::Encode(Encode(v));Executed by:
| 32 | ||||||||||||||||||||||||
| 478 | - | |||||||||||||||||||||||||
| 479 | v = copySign(std::floor(v + 0.5), v); | - | ||||||||||||||||||||||||
| 480 | RETURN_RESULT(Encode(v)); executed 8376 times by 2 tests: return QV4::Encode(Encode(v));Executed by:
| 8376 | ||||||||||||||||||||||||
| 481 | } | - | ||||||||||||||||||||||||
| 482 | - | |||||||||||||||||||||||||
| 483 | ReturnedValue MathObject::method_sign(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 484 | { | - | ||||||||||||||||||||||||
| 485 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-36 | ||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||
| 487 | if (std::isnan(v))
| 4-32 | ||||||||||||||||||||||||
| 488 | RETURN_RESULT(Encode(qt_qnan())); executed 4 times by 1 test: return QV4::Encode(Encode(qt_qnan()));Executed by:
| 4 | ||||||||||||||||||||||||
| 489 | - | |||||||||||||||||||||||||
| 490 | if (qIsNull(v))
| 8-24 | ||||||||||||||||||||||||
| 491 | RETURN_RESULT(Encode(v)); executed 8 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 8 | ||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||
| 493 | RETURN_RESULT(Encode(std::signbit(v) ? -1 : 1)); executed 24 times by 1 test: return QV4::Encode(Encode(std::signbit(v) ? -1 : 1));Executed by:
| 24 | ||||||||||||||||||||||||
| 494 | } | - | ||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||
| 496 | ReturnedValue MathObject::method_sin(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 497 | { | - | ||||||||||||||||||||||||
| 498 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-490 | ||||||||||||||||||||||||
| 499 | if (v == 0.0)
| 24-466 | ||||||||||||||||||||||||
| 500 | RETURN_RESULT(Encode(v)); executed 24 times by 2 tests: return QV4::Encode(Encode(v));Executed by:
| 24 | ||||||||||||||||||||||||
| 501 | else | - | ||||||||||||||||||||||||
| 502 | RETURN_RESULT(Encode(std::sin(v))); executed 466 times by 2 tests: return QV4::Encode(Encode(std::sin(v)));Executed by:
| 466 | ||||||||||||||||||||||||
| 503 | } | - | ||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||
| 505 | ReturnedValue MathObject::method_sinh(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 506 | { | - | ||||||||||||||||||||||||
| 507 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-20 | ||||||||||||||||||||||||
| 508 | if (v == 0.0)
| 8-12 | ||||||||||||||||||||||||
| 509 | RETURN_RESULT(Encode(v)); executed 8 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 8 | ||||||||||||||||||||||||
| 510 | else | - | ||||||||||||||||||||||||
| 511 | RETURN_RESULT(Encode(std::sinh(v))); executed 12 times by 1 test: return QV4::Encode(Encode(std::sinh(v)));Executed by:
| 12 | ||||||||||||||||||||||||
| 512 | } | - | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | ReturnedValue MathObject::method_sqrt(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 515 | { | - | ||||||||||||||||||||||||
| 516 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-28 | ||||||||||||||||||||||||
| 517 | RETURN_RESULT(Encode(std::sqrt(v))); executed 28 times by 1 test: return QV4::Encode(Encode(std::sqrt(v)));Executed by:
| 28 | ||||||||||||||||||||||||
| 518 | } | - | ||||||||||||||||||||||||
| 519 | - | |||||||||||||||||||||||||
| 520 | ReturnedValue MathObject::method_tan(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 521 | { | - | ||||||||||||||||||||||||
| 522 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-20 | ||||||||||||||||||||||||
| 523 | if (v == 0.0)
| 8-12 | ||||||||||||||||||||||||
| 524 | RETURN_RESULT(Encode(v)); executed 8 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 8 | ||||||||||||||||||||||||
| 525 | else | - | ||||||||||||||||||||||||
| 526 | RETURN_RESULT(Encode(std::tan(v))); executed 12 times by 1 test: return QV4::Encode(Encode(std::tan(v)));Executed by:
| 12 | ||||||||||||||||||||||||
| 527 | } | - | ||||||||||||||||||||||||
| 528 | - | |||||||||||||||||||||||||
| 529 | ReturnedValue MathObject::method_tanh(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 530 | { | - | ||||||||||||||||||||||||
| 531 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-20 | ||||||||||||||||||||||||
| 532 | if (v == 0.0)
| 8-12 | ||||||||||||||||||||||||
| 533 | RETURN_RESULT(Encode(v)); executed 8 times by 1 test: return QV4::Encode(Encode(v));Executed by:
| 8 | ||||||||||||||||||||||||
| 534 | else | - | ||||||||||||||||||||||||
| 535 | RETURN_RESULT(Encode(std::tanh(v))); executed 12 times by 1 test: return QV4::Encode(Encode(std::tanh(v)));Executed by:
| 12 | ||||||||||||||||||||||||
| 536 | } | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | ReturnedValue MathObject::method_trunc(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||||||||
| 539 | { | - | ||||||||||||||||||||||||
| 540 | double v = argc ? argv[0].toNumber() : qt_qnan();
| 0-116 | ||||||||||||||||||||||||
| 541 | #ifdef Q_OS_ANDROID // incomplete std :-( | - | ||||||||||||||||||||||||
| 542 | if (std::isnan(v) || qt_is_inf(v) || qIsNull(v)) | - | ||||||||||||||||||||||||
| 543 | RETURN_RESULT(Encode(v)); | - | ||||||||||||||||||||||||
| 544 | // Nearest integer not greater in magnitude: | - | ||||||||||||||||||||||||
| 545 | quint64 whole = std::abs(v); | - | ||||||||||||||||||||||||
| 546 | RETURN_RESULT(Encode(copySign(whole, v))); | - | ||||||||||||||||||||||||
| 547 | #else | - | ||||||||||||||||||||||||
| 548 | RETURN_RESULT(Encode(std::trunc(v))); executed 116 times by 1 test: return QV4::Encode(Encode(std::trunc(v)));Executed by:
| 116 | ||||||||||||||||||||||||
| 549 | #endif | - | ||||||||||||||||||||||||
| 550 | } | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |