-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function for normalising scientific notation
To avoid round-off errors, fractional arguments are converted to integer representations before applying the final exponent. This prevents values like 0.00574012 from being normalised as 5.740119999999999e-3, but means results may not produce the exact same value when applying the exponent: normalise(0.00574012) == [5.74012, -3]; 5.74012 * 10 ** -3 == 0.0057401200000000005; A workaround is to use `parseFloat(result.join("e"));` instead. Should a BigDecimal primitive ever be added to JavaScript, this function could be simplified by replacing the last 3 lines with `value /= 10 ** expo;`.
- Loading branch information
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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