Repository navigation
fix(time): return a plain zero for sub-half-frame negative durations - #83
Merged
Merged
Conversation
framesFor returned -0 for durations smaller than half a frame in the negative direction, because Math.round(-0.03) is -0 and the us > 0 floor guard did not catch it. Harmless downstream, but assert.strictEqual compares with Object.is, so the first test to assert 0 there fails. framesAtRate now branches on the zero case once and returns a plain 0. No change for any positive duration. Part of #82.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #81.
framesForreturns negative zero for durations smaller than half a frame in the negative direction, becauseMath.round(-0.03)is-0and theus > 0floor guard inframesAtRatedoes not catch it.Nothing breaks downstream —
JSON.stringify(-0)is"0"and the value compares equal under==and===— butassert.strictEqual(framesFor(-1_000, 30), 0)throws, becausenode:assert/strictcompares withObject.is. That is a trap for whoever writes that test first, and it is invisible until they do.framesAtRatenow branches on the zero case once and returns a plain0, which reads clearer than the+ 0normalisation trick and keeps the one-frame floor exactly where it was.Validation
a8d31e3withexpected: 0, actual: -0, and passes with the fix.npm test— 666 tests, 666 passed, 0 failed.npm run lint— 125 files, no warnings or errors.No behaviour change for any positive duration: the five measured #69 rows, the one-frame floor, the 30 fps fallback, and the signed result for
-100_000are all untouched.No CHANGELOG entry — the helpers are still under
## [Unreleased]and never shipped with the-0, so the existing bullet already describes what the release will do.Part of #82; the
draftToOtiodeduplication in that issue is still open.