aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2013-03-19 16:04:10 +0100
committerLars Knoll <lars.knoll@digia.com>2013-03-20 09:59:40 +0100
commit5fefa66d5d6140c392af76326c8fb2d3f4f70261 (patch)
treeb50e2149cc6bf598e8ce839a5d88aa56cba1446d /src
parent4a91ef5ec5c79a0173933908e75157014c867af8 (diff)
Fix module operation to conform to IEEE 754 arithmic.
When the two operands are integers, and the result is 0 AND the left-hand side is negative, then discard it and do the calculation based on doubles. The reason is that the integer mod can only return +0, while (-1 % -1) and (-1 % 1) should return -0. Change-Id: I676e5bbdf3a7dcb29006d9101a9e5e7c33467c49 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/v4/qv4runtime.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/v4/qv4runtime.h b/src/v4/qv4runtime.h
index 74549c68a1..09581c9f4f 100644
--- a/src/v4/qv4runtime.h
+++ b/src/v4/qv4runtime.h
@@ -495,8 +495,11 @@ inline void __qmljs_mod(ExecutionContext *ctx, Value *result, const Value &left,
TRACE2(left, right);
if (Value::integerCompatible(left, right) && right.integerValue() != 0) {
- *result = Value::fromInt32(left.integerValue() % right.integerValue());
- return;
+ int intRes = left.integerValue() % right.integerValue();
+ if (intRes != 0 || left.integerValue() >= 0) {
+ *result = Value::fromInt32(intRes);
+ return;
+ }
}
double lval = __qmljs_to_number(left, ctx);