aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-02-13 12:02:19 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-02-19 10:49:03 +0000
commit373ce8878321aa561b55131bada78ad4a2ce8427 (patch)
tree0b64429ea79163f1f13b4073bbe60040047d0540 /src/qml/jsruntime
parent6f264b755501fd322d1e357187b42120210a7ba3 (diff)
Cleanup math function includes and usage
Use std::math on floats and doubles, and qMath on qreals, and only include the math headers actually needed. Change-Id: I1d511d7b1bac0050eaa947c7baee760b736858bf Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp8
-rw-r--r--src/qml/jsruntime/qv4errorobject.cpp5
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp1
-rw-r--r--src/qml/jsruntime/qv4mathobject.cpp64
-rw-r--r--src/qml/jsruntime/qv4numberobject.cpp10
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp2
-rw-r--r--src/qml/jsruntime/qv4regexpobject.cpp1
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp7
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp11
-rw-r--r--src/qml/jsruntime/qv4typedarray.cpp4
10 files changed, 49 insertions, 64 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index c74995faee..28f0f2e044 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -37,14 +37,10 @@
#include "qv4scopedvalue_p.h"
#include "qv4runtime_p.h"
-#include <QtCore/qnumeric.h>
-#include <QtCore/qmath.h>
+#include <QtCore/QDebug>
#include <QtCore/QDateTime>
#include <QtCore/QStringList>
-#include <QtCore/QDebug>
-#include <cmath>
-#include <qmath.h>
-#include <qnumeric.h>
+
#include <time.h>
#include <private/qqmljsengine_p.h>
diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp
index be9f1e8df7..119ad93e63 100644
--- a/src/qml/jsruntime/qv4errorobject.cpp
+++ b/src/qml/jsruntime/qv4errorobject.cpp
@@ -34,14 +34,9 @@
#include "qv4errorobject_p.h"
#include "qv4mm_p.h"
-#include <QtCore/qnumeric.h>
-#include <QtCore/qmath.h>
#include <QtCore/QDateTime>
#include <QtCore/QStringList>
#include <QtCore/QDebug>
-#include <cmath>
-#include <qmath.h>
-#include <qnumeric.h>
#include <private/qqmljsengine_p.h>
#include <private/qqmljslexer_p.h>
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 303e654fe3..5be638e909 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -52,7 +52,6 @@
#include "private/qlocale_tools_p.h"
#include "private/qqmlbuiltinfunctions_p.h"
-#include <QtCore/qmath.h>
#include <QtCore/QDebug>
#include <algorithm>
#include "qv4alloca_p.h"
diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp
index 9d2c496bd0..473e05bf88 100644
--- a/src/qml/jsruntime/qv4mathobject.cpp
+++ b/src/qml/jsruntime/qv4mathobject.cpp
@@ -34,13 +34,13 @@
#include "qv4mathobject_p.h"
#include "qv4objectproto_p.h"
-#include <cmath>
-#include <qmath.h>
-#include <qnumeric.h>
-
#include <QtCore/qdatetime.h>
+#include <QtCore/qmath.h>
+#include <QtCore/qnumeric.h>
#include <QtCore/qthreadstorage.h>
+#include <cmath>
+
using namespace QV4;
DEFINE_OBJECT_VTABLE(MathObject);
@@ -53,14 +53,14 @@ Heap::MathObject::MathObject(ExecutionEngine *e)
Scope scope(e);
ScopedObject m(scope, this);
- m->defineReadonlyProperty(QStringLiteral("E"), Primitive::fromDouble(::exp(1.0)));
- m->defineReadonlyProperty(QStringLiteral("LN2"), Primitive::fromDouble(::log(2.0)));
- m->defineReadonlyProperty(QStringLiteral("LN10"), Primitive::fromDouble(::log(10.0)));
- m->defineReadonlyProperty(QStringLiteral("LOG2E"), Primitive::fromDouble(1.0/::log(2.0)));
- m->defineReadonlyProperty(QStringLiteral("LOG10E"), Primitive::fromDouble(1.0/::log(10.0)));
- m->defineReadonlyProperty(QStringLiteral("PI"), Primitive::fromDouble(qt_PI));
- m->defineReadonlyProperty(QStringLiteral("SQRT1_2"), Primitive::fromDouble(::sqrt(0.5)));
- m->defineReadonlyProperty(QStringLiteral("SQRT2"), Primitive::fromDouble(::sqrt(2.0)));
+ m->defineReadonlyProperty(QStringLiteral("E"), Primitive::fromDouble(M_E));
+ m->defineReadonlyProperty(QStringLiteral("LN2"), Primitive::fromDouble(M_LN2));
+ m->defineReadonlyProperty(QStringLiteral("LN10"), Primitive::fromDouble(M_LN10));
+ m->defineReadonlyProperty(QStringLiteral("LOG2E"), Primitive::fromDouble(M_LOG2E));
+ m->defineReadonlyProperty(QStringLiteral("LOG10E"), Primitive::fromDouble(M_LOG10E));
+ m->defineReadonlyProperty(QStringLiteral("PI"), Primitive::fromDouble(M_PI));
+ m->defineReadonlyProperty(QStringLiteral("SQRT1_2"), Primitive::fromDouble(M_SQRT1_2));
+ m->defineReadonlyProperty(QStringLiteral("SQRT2"), Primitive::fromDouble(M_SQRT2));
m->defineDefaultProperty(QStringLiteral("abs"), QV4::MathObject::method_abs, 1);
m->defineDefaultProperty(QStringLiteral("acos"), QV4::MathObject::method_acos, 1);
@@ -117,7 +117,7 @@ ReturnedValue MathObject::method_acos(CallContext *context)
if (v > 1)
return Encode(qSNaN());
- return Encode(::acos(v));
+ return Encode(std::acos(v));
}
ReturnedValue MathObject::method_asin(CallContext *context)
@@ -126,7 +126,7 @@ ReturnedValue MathObject::method_asin(CallContext *context)
if (v > 1)
return Encode(qSNaN());
else
- return Encode(::asin(v));
+ return Encode(std::asin(v));
}
ReturnedValue MathObject::method_atan(CallContext *context)
@@ -135,7 +135,7 @@ ReturnedValue MathObject::method_atan(CallContext *context)
if (v == 0.0)
return Encode(v);
else
- return Encode(::atan(v));
+ return Encode(std::atan(v));
}
ReturnedValue MathObject::method_atan2(CallContext *context)
@@ -148,12 +148,12 @@ ReturnedValue MathObject::method_atan2(CallContext *context)
if ((v1 == 0.0) && (v2 == 0.0)) {
if ((copySign(1.0, v1) == 1.0) && (copySign(1.0, v2) == -1.0)) {
- return Encode(qt_PI);
+ return Encode(M_PI);
} else if ((copySign(1.0, v1) == -1.0) && (copySign(1.0, v2) == -1.0)) {
- return Encode(-qt_PI);
+ return Encode(-M_PI);
}
}
- return Encode(::atan2(v1, v2));
+ return Encode(std::atan2(v1, v2));
}
ReturnedValue MathObject::method_ceil(CallContext *context)
@@ -162,13 +162,13 @@ ReturnedValue MathObject::method_ceil(CallContext *context)
if (v < 0.0 && v > -1.0)
return Encode(copySign(0, -1.0));
else
- return Encode(::ceil(v));
+ return Encode(std::ceil(v));
}
ReturnedValue MathObject::method_cos(CallContext *context)
{
double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
- return Encode(::cos(v));
+ return Encode(std::cos(v));
}
ReturnedValue MathObject::method_exp(CallContext *context)
@@ -180,14 +180,14 @@ ReturnedValue MathObject::method_exp(CallContext *context)
else
return Encode(qInf());
} else {
- return Encode(::exp(v));
+ return Encode(std::exp(v));
}
}
ReturnedValue MathObject::method_floor(CallContext *context)
{
double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
- return Encode(::floor(v));
+ return Encode(std::floor(v));
}
ReturnedValue MathObject::method_log(CallContext *context)
@@ -196,7 +196,7 @@ ReturnedValue MathObject::method_log(CallContext *context)
if (v < 0)
return Encode(qSNaN());
else
- return Encode(::log(v));
+ return Encode(std::log(v));
}
ReturnedValue MathObject::method_max(CallContext *context)
@@ -239,12 +239,12 @@ ReturnedValue MathObject::method_pow(CallContext *context)
return Encode(qInf());
} else if ((x == 0) && copySign(1.0, x) == -1.0) {
if (y < 0) {
- if (::fmod(-y, 2.0) == 1.0)
+ if (std::fmod(-y, 2.0) == 1.0)
return Encode(-qInf());
else
return Encode(qInf());
} else if (y > 0) {
- if (::fmod(y, 2.0) == 1.0)
+ if (std::fmod(y, 2.0) == 1.0)
return Encode(copySign(0, -1.0));
else
return Encode(0);
@@ -254,12 +254,12 @@ ReturnedValue MathObject::method_pow(CallContext *context)
#ifdef Q_OS_AIX
else if (qIsInf(x) && copySign(1.0, x) == -1.0) {
if (y > 0) {
- if (::fmod(y, 2.0) == 1.0)
+ if (std::fmod(y, 2.0) == 1.0)
return Encode(-qInf());
else
return Encode(qInf());
} else if (y < 0) {
- if (::fmod(-y, 2.0) == 1.0)
+ if (std::fmod(-y, 2.0) == 1.0)
return Encode(copySign(0, -1.0));
else
return Encode(0);
@@ -267,7 +267,7 @@ ReturnedValue MathObject::method_pow(CallContext *context)
}
#endif
else {
- return Encode(::pow(x, y));
+ return Encode(std::pow(x, y));
}
// ###
return Encode(qSNaN());
@@ -287,20 +287,20 @@ ReturnedValue MathObject::method_random(CallContext *context)
ReturnedValue MathObject::method_round(CallContext *context)
{
double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
- v = copySign(::floor(v + 0.5), v);
+ 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();
- return Encode(::sin(v));
+ return Encode(std::sin(v));
}
ReturnedValue MathObject::method_sqrt(CallContext *context)
{
double v = context->argc() ? context->args()[0].toNumber() : qSNaN();
- return Encode(::sqrt(v));
+ return Encode(std::sqrt(v));
}
ReturnedValue MathObject::method_tan(CallContext *context)
@@ -309,6 +309,6 @@ ReturnedValue MathObject::method_tan(CallContext *context)
if (v == 0.0)
return Encode(v);
else
- return Encode(::tan(v));
+ return Encode(std::tan(v));
}
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp
index 4135ab064b..d8c9d89369 100644
--- a/src/qml/jsruntime/qv4numberobject.cpp
+++ b/src/qml/jsruntime/qv4numberobject.cpp
@@ -139,22 +139,22 @@ ReturnedValue NumberPrototype::method_toString(CallContext *ctx)
negative = true;
num = -num;
}
- double frac = num - ::floor(num);
+ double frac = num - std::floor(num);
num = Primitive::toInteger(num);
do {
- char c = (char)::fmod(num, radix);
+ char c = (char)std::fmod(num, radix);
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
str.prepend(QLatin1Char(c));
- num = ::floor(num / radix);
+ num = std::floor(num / radix);
} while (num != 0);
if (frac != 0) {
str.append(QLatin1Char('.'));
do {
frac = frac * radix;
- char c = (char)::floor(frac);
+ char c = (char)std::floor(frac);
c = (c < 10) ? (c + '0') : (c - 10 + 'a');
str.append(QLatin1Char(c));
- frac = frac - ::floor(frac);
+ frac = frac - std::floor(frac);
} while (frac != 0);
}
if (negative)
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index a74ebafc8d..9356ea434e 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -39,8 +39,6 @@
#include "qv4runtime_p.h"
#include "qv4objectiterator_p.h"
-#include <QtCore/qnumeric.h>
-#include <QtCore/qmath.h>
#include <QtCore/QDateTime>
#include <QtCore/QStringList>
diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp
index dccd3ee1a8..f6e88e62b7 100644
--- a/src/qml/jsruntime/qv4regexpobject.cpp
+++ b/src/qml/jsruntime/qv4regexpobject.cpp
@@ -48,7 +48,6 @@
#include <qv4codegen_p.h>
#include "private/qlocale_tools_p.h"
-#include <QtCore/qmath.h>
#include <QtCore/QDebug>
#include <QtCore/qregexp.h>
#include <cassert>
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 607a68831f..20707d073b 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -50,14 +50,13 @@
#include <private/qv8engine_p.h>
#endif
-#include <QtCore/qmath.h>
-#include <QtCore/qnumeric.h>
#include <QtCore/QDebug>
-#include <cstdio>
#include <cassert>
-#include <typeinfo>
+#include <cstdio>
#include <stdlib.h>
+#include <wtf/MathExtras.h>
+
#include "../../3rdparty/double-conversion/double-conversion.h"
#ifdef QV4_COUNT_RUNTIME_FUNCTIONS
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index 82a7080fc1..a589ae94c3 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -38,15 +38,10 @@
#include "qv4objectproto_p.h"
#include "qv4mm_p.h"
#include "qv4scopedvalue_p.h"
-#include <QtCore/qnumeric.h>
-#include <QtCore/qmath.h>
+
#include <QtCore/QDateTime>
-#include <QtCore/QStringList>
#include <QtCore/QDebug>
-#include <cmath>
-#include <qmath.h>
-#include <qnumeric.h>
-#include <cassert>
+#include <QtCore/QStringList>
#include <private/qqmljsengine_p.h>
#include <private/qqmljslexer_p.h>
@@ -55,6 +50,8 @@
#include <qv4jsir_p.h>
#include <qv4codegen_p.h>
+#include <cassert>
+
#ifndef Q_OS_WIN
# include <time.h>
# ifndef Q_OS_VXWORKS
diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp
index a590b0df07..429ec96f0b 100644
--- a/src/qml/jsruntime/qv4typedarray.cpp
+++ b/src/qml/jsruntime/qv4typedarray.cpp
@@ -33,6 +33,8 @@
#include "qv4typedarray_p.h"
#include "qv4arraybuffer_p.h"
+#include <cmath>
+
using namespace QV4;
DEFINE_OBJECT_VTABLE(TypedArrayCtor);
@@ -85,7 +87,7 @@ void UInt8ClampedArrayWrite(ExecutionEngine *e, char *data, int index, const Val
data[index] = (unsigned char)(255);
return;
}
- double f = floor(d);
+ double f = std::floor(d);
if (f + 0.5 < d) {
data[index] = (unsigned char)(f + 1);
return;