aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4mathobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime/qv4mathobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4mathobject.cpp109
1 files changed, 54 insertions, 55 deletions
diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp
index 5d1dbe69e1..cb17583b98 100644
--- a/src/qml/jsruntime/qv4mathobject.cpp
+++ b/src/qml/jsruntime/qv4mathobject.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQml module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -36,7 +42,7 @@
#include <QtCore/qdatetime.h>
#include <QtCore/qmath.h>
-#include <QtCore/qnumeric.h>
+#include <QtCore/private/qnumeric_p.h>
#include <QtCore/qthreadstorage.h>
#include <cmath>
@@ -79,22 +85,15 @@ Heap::MathObject::MathObject()
m->defineDefaultProperty(QStringLiteral("tan"), QV4::MathObject::method_tan, 1);
}
-/* copies the sign from y to x and returns the result */
-static double copySign(double x, double y)
+static Q_ALWAYS_INLINE double copySign(double x, double y)
{
- uchar *xch = (uchar *)&x;
- uchar *ych = (uchar *)&y;
- if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
- xch[0] = (xch[0] & 0x7f) | (ych[0] & 0x80);
- else
- xch[7] = (xch[7] & 0x7f) | (ych[7] & 0x80);
- return x;
+ return ::copysign(x, y);
}
ReturnedValue MathObject::method_abs(CallContext *context)
{
if (!context->argc())
- return Encode(qSNaN());
+ return Encode(qt_qnan());
if (context->args()[0].isInteger()) {
int i = context->args()[0].integerValue();
@@ -112,7 +111,7 @@ ReturnedValue MathObject::method_acos(CallContext *context)
{
double v = context->argc() ? context->args()[0].toNumber() : 2;
if (v > 1)
- return Encode(qSNaN());
+ return Encode(qt_qnan());
return Encode(std::acos(v));
}
@@ -121,14 +120,14 @@ ReturnedValue MathObject::method_asin(CallContext *context)
{
double v = context->argc() ? context->args()[0].toNumber() : 2;
if (v > 1)
- return Encode(qSNaN());
+ return Encode(qt_qnan());
else
return Encode(std::asin(v));
}
ReturnedValue MathObject::method_atan(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
if (v == 0.0)
return Encode(v);
else
@@ -137,10 +136,10 @@ ReturnedValue MathObject::method_atan(CallContext *context)
ReturnedValue MathObject::method_atan2(CallContext *context)
{
- double v1 = context->argc() ? context->args()[0].toNumber() : qSNaN();
- double v2 = context->argc() > 1 ? context->args()[1].toNumber() : qSNaN();
+ double v1 = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ double v2 = context->argc() > 1 ? context->args()[1].toNumber() : qt_qnan();
- if ((v1 < 0) && qIsFinite(v1) && qIsInf(v2) && (copySign(1.0, v2) == 1.0))
+ if ((v1 < 0) && qt_is_finite(v1) && qt_is_inf(v2) && (copySign(1.0, v2) == 1.0))
return Encode(copySign(0, -1.0));
if ((v1 == 0.0) && (v2 == 0.0)) {
@@ -155,7 +154,7 @@ ReturnedValue MathObject::method_atan2(CallContext *context)
ReturnedValue MathObject::method_ceil(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
if (v < 0.0 && v > -1.0)
return Encode(copySign(0, -1.0));
else
@@ -164,18 +163,18 @@ ReturnedValue MathObject::method_ceil(CallContext *context)
ReturnedValue MathObject::method_cos(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
return Encode(std::cos(v));
}
ReturnedValue MathObject::method_exp(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
- if (qIsInf(v)) {
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ if (qt_is_inf(v)) {
if (copySign(1.0, v) == -1.0)
return Encode(0);
else
- return Encode(qInf());
+ return Encode(qt_inf());
} else {
return Encode(std::exp(v));
}
@@ -183,22 +182,22 @@ ReturnedValue MathObject::method_exp(CallContext *context)
ReturnedValue MathObject::method_floor(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
return Encode(std::floor(v));
}
ReturnedValue MathObject::method_log(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
if (v < 0)
- return Encode(qSNaN());
+ return Encode(qt_qnan());
else
return Encode(std::log(v));
}
ReturnedValue MathObject::method_max(CallContext *context)
{
- double mx = -qInf();
+ double mx = -qt_inf();
for (int i = 0; i < context->argc(); ++i) {
double x = context->args()[i].toNumber();
if (x > mx || std::isnan(x))
@@ -209,7 +208,7 @@ ReturnedValue MathObject::method_max(CallContext *context)
ReturnedValue MathObject::method_min(CallContext *context)
{
- double mx = qInf();
+ double mx = qt_inf();
for (int i = 0; i < context->argc(); ++i) {
double x = context->args()[i].toNumber();
if ((x == 0 && mx == x && copySign(1.0, x) == -1.0)
@@ -222,24 +221,24 @@ ReturnedValue MathObject::method_min(CallContext *context)
ReturnedValue MathObject::method_pow(CallContext *context)
{
- double x = context->argc() > 0 ? context->args()[0].toNumber() : qSNaN();
- double y = context->argc() > 1 ? context->args()[1].toNumber() : qSNaN();
+ double x = context->argc() > 0 ? context->args()[0].toNumber() : qt_qnan();
+ double y = context->argc() > 1 ? context->args()[1].toNumber() : qt_qnan();
if (std::isnan(y))
- return Encode(qSNaN());
+ return Encode(qt_qnan());
if (y == 0) {
return Encode(1);
} else if (((x == 1) || (x == -1)) && std::isinf(y)) {
- return Encode(qSNaN());
+ return Encode(qt_qnan());
} else if (((x == 0) && copySign(1.0, x) == 1.0) && (y < 0)) {
return Encode(qInf());
} else if ((x == 0) && copySign(1.0, x) == -1.0) {
if (y < 0) {
if (std::fmod(-y, 2.0) == 1.0)
- return Encode(-qInf());
+ return Encode(-qt_inf());
else
- return Encode(qInf());
+ return Encode(qt_inf());
} else if (y > 0) {
if (std::fmod(y, 2.0) == 1.0)
return Encode(copySign(0, -1.0));
@@ -249,12 +248,12 @@ ReturnedValue MathObject::method_pow(CallContext *context)
}
#ifdef Q_OS_AIX
- else if (qIsInf(x) && copySign(1.0, x) == -1.0) {
+ else if (qt_is_inf(x) && copySign(1.0, x) == -1.0) {
if (y > 0) {
if (std::fmod(y, 2.0) == 1.0)
- return Encode(-qInf());
+ return Encode(-qt_inf());
else
- return Encode(qInf());
+ return Encode(qt_inf());
} else if (y < 0) {
if (std::fmod(-y, 2.0) == 1.0)
return Encode(copySign(0, -1.0));
@@ -267,7 +266,7 @@ ReturnedValue MathObject::method_pow(CallContext *context)
return Encode(std::pow(x, y));
}
// ###
- return Encode(qSNaN());
+ return Encode(qt_qnan());
}
Q_GLOBAL_STATIC(QThreadStorage<bool *>, seedCreatedStorage);
@@ -288,26 +287,26 @@ ReturnedValue MathObject::method_random(CallContext *context)
ReturnedValue MathObject::method_round(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
v = copySign(std::floor(v + 0.5), v);
return Encode(v);
}
ReturnedValue MathObject::method_sin(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
return Encode(std::sin(v));
}
ReturnedValue MathObject::method_sqrt(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
return Encode(std::sqrt(v));
}
ReturnedValue MathObject::method_tan(CallContext *context)
{
- double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
+ double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
if (v == 0.0)
return Encode(v);
else