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)

x86
macOS
defect

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)

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?
Looks like it might be an FP rounding issue.
Flags: blocking1.9.2? → blocking1.9.2+
Priority: -- → P3
Flags: in-testsuite?
Assignee: general → jorendorff
Priority: P3 → P2
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.
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).
Summary: TM: Different values with testcase containing for, function, return, uneval → TM: Different values for modulo of negative number (-2 % 2)
Attached patch v1Splinter Review
one-character fix + test
Attachment #408006 - Flags: review?(graydon)
Attachment #408006 - Flags: review?(graydon) → review+
Flags: in-testsuite? → in-testsuite+
Whiteboard: fixed-in-tracemonkey
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
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.
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.

Attachment

General

Created:
Updated:
Size: