Closed
Bug 505003
Opened 16 years ago
Closed 16 years ago
TM: Different values for modulo of negative number (-2 % 2)
Categories
(Core :: JavaScript Engine, defect, P2)
Tracking
()
VERIFIED
FIXED
Tracking | Status | |
---|---|---|
status1.9.2 | --- | beta4-fixed |
People
(Reporter: gkw, Assigned: jorendorff)
Details
(Keywords: testcase, Whiteboard: fixed-in-tracemonkey)
Attachments
(2 files)
120 bytes,
application/x-javascript
|
Details | |
1.14 KB,
patch
|
graydon
:
review+
|
Details | Diff | Splinter Review |
v = 1
for (e = 0; e < 3; ++e) {
v -= (e = (v ^ e))
for (c = 0; c < 3; ++c) {
v %= (function () {
return (e)
})()
}
}
print(uneval(this))
outputs a different value for "v" on TM branch with and without -j.
=====
$ ~/Desktop/tm-30366-b8d41dbdef7f/js-opt-tm-intelmac
js> v = 1
1
js> for (e = 0; e < 3; ++e) {
v -= (e = (v ^ e))
for (c = 0; c < 3; ++c) {
v %= (function () {
return (e)
})()
}
}
0
js> print(uneval(this))
({v:-0, e:3, c:3})
js>
$ ~/Desktop/tm-30366-b8d41dbdef7f/js-opt-tm-intelmac -j
js> v = 1
1
js> for (e = 0; e < 3; ++e) {
v -= (e = (v ^ e))
for (c = 0; c < 3; ++c) {
v %= (function () {
return (e)
})()
}
}
0
js> print(uneval(this))
({v:0, e:3, c:3})
js>
Flags: blocking1.9.2?
Comment 1•16 years ago
|
||
Looks like it might be an FP rounding issue.
Comment 2•16 years ago
|
||
Updated•16 years ago
|
Flags: blocking1.9.2? → blocking1.9.2+
Priority: -- → P3
![]() |
Reporter | |
Updated•16 years ago
|
Flags: in-testsuite?
Assignee | ||
Updated•16 years ago
|
Assignee: general → jorendorff
Updated•16 years ago
|
Priority: P3 → P2
Assignee | ||
Comment 3•16 years ago
|
||
function f(v, e) {
for (var i = 0; i < 3; i++)
v %= e;
return v;
}
f(0, 1);
assertEq(f(-2, 2), -0);
First time through, we record an integer modulus operation. We also emit a guard that should trip if the result is -0. Second time through, the result should be -0 but when we get back into the interpreter it's 0.
Investigating.
Assignee | ||
Comment 4•16 years ago
|
||
We aren't side-exiting.
26: eq2 = eq ld2, 0
27: xt1: xt eq2 -> pc=0xa02dd3c imacpc=(nil) sp+16 rp+0 (GuardID=002)
28: div1 = div ld1, ld2
29: mod1 = mod div1
30: eq3 = eq mod1, 0
31: jf eq3 -> label2
32: lt1 = lt ld2, 0
33: xt2: xt lt1 -> pc=0xa02dd3c imacpc=(nil) sp+16 rp+0 (GuardID=003)
34: label2:
On line 32, we should be checking for negative lhs (ld1), not negative rhs (ld2).
Assignee | ||
Updated•16 years ago
|
Summary: TM: Different values with testcase containing for, function, return, uneval → TM: Different values for modulo of negative number (-2 % 2)
Assignee | ||
Comment 5•16 years ago
|
||
one-character fix + test
Attachment #408006 -
Flags: review?(graydon)
Updated•16 years ago
|
Attachment #408006 -
Flags: review?(graydon) → review+
![]() |
Reporter | |
Updated•16 years ago
|
Keywords: checkin-needed
Assignee | ||
Comment 6•16 years ago
|
||
Flags: in-testsuite? → in-testsuite+
Whiteboard: fixed-in-tracemonkey
![]() |
Reporter | |
Updated•16 years ago
|
Keywords: checkin-needed
Comment 7•16 years ago
|
||
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
Comment 8•16 years ago
|
||
status1.9.2:
--- → final-fixed
Comment 9•16 years ago
|
||
Gentlemen,
I am a stranger here, and I freely admit that I don't know what you're doing, exactly, and I don't want to take the time to figure that out. Neither do I want to waste your time.
What I do know is that programming language libraries implement math functions like mod and div differently, and they don't necessarily do what you would expect. In the general case where operands to these functions may have either sign, it behooves the careful programmer to test the output. More at <a href="http://en.wikipedia.org/wiki/Modular_arithmetic">Wikipedia</a>. The short version is that the mathematical operations mod and remainder are often confused or conflated, and they are NOT the same.
![]() |
Reporter | |
Comment 10•13 years ago
|
||
A type of test for this bug has already been landed because it is already marked in-testsuite+ -> VERIFIED.
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•