Repository navigation
Conversation
…ng first applyPrecisionHandling() only moved to the next unit when toPrecision() returned e-notation. Since avoidwork#404 the value is no longer rounded to `round` before the precision pass, so 999.999 kB with precision 4 gives "1000" and printed "1000 kB" (filesize(999999) prints "1 MB"). Move up when the significant-digit form reaches `ceil` too. When the unit moved, the recomputed value was still rounded to `round` decimals before toPrecision(), the same double rounding avoidwork#399 fixed in the main path: 1000 KiB printed "0.980 MiB" instead of "0.977 MiB", and with round: 0, 392 B at precision 1 printed "0 kB". Take the new value straight from the input; roundingFunc and round are no longer needed here. Fixes avoidwork#413
This branch has not been deployed
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
Two fixes in
applyPrecisionHandling(), the step that moves aprecisionresult to the next unit:(999.999).toPrecision(4)is"1000", which has noe, sofilesize(999999, { precision: 4 })printed1000 kB(and1048575withbase: 2printed1024 KiB). It now prints1.000 MB/1.000 MiB, as 11.0.30 did and asfilesize(999999)→1 MBdoes.roundbeforetoPrecision()after the move. This is the same double rounding fix:precisionis applied afterround, rounding an already-rounded value #399/fix: apply precision before round for decimal units #404 removed from the main path.filesize(1024000, { base: 2, precision: 3 })printed0.980 MiB(true value 0.9766), and withround: 0it printed0:filesize(392, { precision: 1, round: 0 })gave0 kB. The new value now comes straight from the input, soroundingFuncandroundare dropped from the helper's arguments (call site, helper tests and TECHNICAL_DOCUMENTATION.md updated).Two existing pins of
0.990 GiB/0.990 gibibytesfor1058223158are updated to0.986: 1058223158 / 2^30 = 0.98555, so three significant digits are0.986.Type of Change
Related Issues
Fixes #413
Testing
Precision option(ceiling bump for SI / IEC / bits / negative / object and exponent output / forced exponent, and digits kept after the bump). They fail on master (1000 kB,0.980 MiB) and pass with the fix.npm test: lint clean, 281 pass / 0 fail, coverage still 100% for all files.precisionis 0. Every change is in the bump path above. Checking the results against the exact value: above whole bytes, no result now reaches the ceiling or is off by more than half a unit in the last significant digit (master had ~198k such results in that run, mostly theround: 0case).Checklist
npm testpassesnpm run buildsucceeds