Use exponential notation for rendering Amount values#104
Open
jessealama wants to merge 17 commits intomainfrom
Open
Use exponential notation for rendering Amount values#104jessealama wants to merge 17 commits intomainfrom
jessealama wants to merge 17 commits intomainfrom
Conversation
|
eemeli
requested changes
Apr 30, 2026
eemeli
reviewed
Apr 30, 2026
Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
Adds two abstract operations to Amount: - RenderStringInExponentialNotation: takes a String in StrDecimalLiteral form and rewrites it in canonical exponential form (one nonzero integer digit, optional fractional part, signed unpadded exponent), preserving the precision of the input. It uses StringIntlMV to recover the mathematical value and significant-digit count, then formats the mantissa via CreateFormatterObject + FormatNumericToString configured for fraction digits = digitCount - 1 (which sidesteps the 21 cap on the significant-digit slots). - RenderBigIntInExponentialNotation: takes a BigInt and rewrites it in canonical exponential form, absorbing trailing zeros into the exponent. Wires these through the constructor and convertTo so any String stored in [[AmountValue]] is already in canonical exponential form, and through toString so Number-backed values use Number.prototype.toExponential and BigInt-backed values use the new AO. Resolves the TODO left in #102.
Replaces the explicit StrDecimalLiteral parse + StringIntlMV dance with a single call to ToIntlMathematicalValue, which returns the same (value, digit count) pair and also resolves the NaN/Infinity special cases through its return value rather than by string comparison.
Co-authored-by: Eemeli Aro <eemeli@mozilla.com>
70d7e0c to
736d70c
Compare
jessealama
added a commit
that referenced
this pull request
May 5, 2026
The exponential-notation rendering of Amount values is the subject of PR #104. Per Richard Gibson's suggestion, this PR is narrowed to cover only the bracket-and-tilde serialization style. Reverts the exponential example values, the unit-name canonicalization (kg → kilogram), and the 'canonical exponential notation' wording in toString's description. Drops the spec algorithm's placeholder TODO line, since exponential normalization is fleshed out in PR #104.
eemeli
requested changes
May 5, 2026
eemeli
approved these changes
May 5, 2026
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.
Resolves the toString TODO with a new AO,
RenderInExponentialNotation(value, sigDigits), which renders a mathematical value in canonical exponential notation.BigInt rendering here doesn't strip trailing zeros, so
100000nnow serializes as"1.00000e+5", which makes things uniform with howNumbersandStringsare handled.An editorial note records that the AO does essentially overlaps with
Number.prototype.toExponentialand that the two should eventually share an extracted operation.