Skip to content

Commit

Permalink
Adding failing Math.imul tests, and a fix.
Browse files Browse the repository at this point in the history
Fixes #271.
  • Loading branch information
ljharb committed Jul 15, 2014
1 parent 687d1a4 commit b74ceb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,8 @@

imul: function(x, y) {
// taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
x = ES.ToUint32(x);
y = ES.ToUint32(y);
var ah = (x >>> 16) & 0xffff;
var al = x & 0xffff;
var bh = (y >>> 16) & 0xffff;
Expand Down
12 changes: 12 additions & 0 deletions test/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ describe('Math', function() {
expect(Math.imul(1.9, 7)).to.equal(7);
expect(Math.imul(7, 1.9)).to.equal(7);
});

it('should be correct for objects with valueOf', function() {
var x = {
x: 0,
valueOf: function () { return ++this.x; }
};
expect(Math.imul(x, 1)).to.equal(1);
expect(Math.imul(1, x)).to.equal(2);
expect(Math.imul(x, 1)).to.equal(3);
expect(Math.imul(1, x)).to.equal(4);
expect(Math.imul(x, 1)).to.equal(5);
});
});

describe('Math.fround', function() {
Expand Down

0 comments on commit b74ceb2

Please sign in to comment.