Always floor time instead of rounding up #49
Merged
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.
Currently the rounding logic is slightly broken. For instance, in the unit tests,
95543ms
, ie.1 min 35 sec 543 ms
rounded to 3 second decimal digits withcolonNotation=true
yields1:35.580
(this should obviously be1:35.543
). I also propose that time rounding should always floor the value, not regular rounding up when the remainder is>=0.5
, as otherwise the the interval between 1-2 seconds will only be 0.5 seconds long, as it is rounded to 2 seconds after as time passes 1500 ms.This PR changes rounding so that it always rounds down. For example, with zero second precision,
1999 ms
is 1 second, not 2 seconds. A new flooring function is introduced that adds an epsilon term prior to flooring to avoid floating point errors, which replaces the current logic. Without it, one the verbose unit tests for5254ms
rounded to 4 second decimal places would yield5.2539 seconds
, not5.2540 seconds
).