Skip to content

Commit

Permalink
fix: handle floating point in hrtime (#210)
Browse files Browse the repository at this point in the history
Fixes #207
  • Loading branch information
SimenB authored and fatso83 committed Sep 19, 2018
1 parent cbaa8ba commit c4ee56d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lolex-src.js
Expand Up @@ -101,7 +101,7 @@ function withGlobal(_global) {
* % operator that also works for negative numbers
*/
function fixedModulo(n, m) {
return ((n % m) + m) % m;
return Math.round(((n % m) + m) % m);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions test/lolex-test.js
Expand Up @@ -2384,6 +2384,14 @@ describe("lolex", function () {
assert.same(result[0], 1);
assert.same(result[1], 0);
});

it("should handle floating point", function () {
var clock = lolex.createClock();
clock.tick(1022.7791);
var result = clock.hrtime([0, 20000000]);

assert.equals(result, [1, 2779100]);
});
});
}
if (nextTickPresent) {
Expand Down

0 comments on commit c4ee56d

Please sign in to comment.