aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-01-28 17:50:02 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-02-02 11:23:48 +0000
commit15f2d3f0d5b0acad5d5438f510069a620177c98c (patch)
tree7e55e56de255e261877492503db2352879f9c39d /src/qml
parent0c530f28733f15f86c1d83fd9d7542b3e3131d1d (diff)
Fix Math.round edge-case
Round 0.49999999999999994 correctly Task-number: QTBUG-90444 Change-Id: I0e8a19fb52540c6e976308089a782f1f472bc77f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4mathobject.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp
index c6b74e7aba..382185657e 100644
--- a/src/qml/jsruntime/qv4mathobject.cpp
+++ b/src/qml/jsruntime/qv4mathobject.cpp
@@ -474,11 +474,14 @@ ReturnedValue MathObject::method_random(const FunctionObject *, const Value *, c
ReturnedValue MathObject::method_round(const FunctionObject *, const Value *, const Value *argv, int argc)
{
double v = argc ? argv[0].toNumber() : qt_qnan();
- if (std::isnan(v) || qt_is_inf(v) || qIsNull(v))
+ if (!std::isfinite(v))
RETURN_RESULT(Encode(v));
- v = copySign(std::floor(v + 0.5), v);
- RETURN_RESULT(Encode(v));
+ if (v < 0.5 && v >= -0.5)
+ v = std::copysign(0.0, v);
+ else
+ v = std::floor(v + 0.5);
+ RETURN_RESULT(Encode(v));
}
ReturnedValue MathObject::method_sign(const FunctionObject *, const Value *, const Value *argv, int argc)