Skip to content

Conversation

jessealama
Copy link
Collaborator

This PR extends the Amount constructor to allow Infinity, -Infinity, NaN, and -0, both as Numbers and as Strings. We stipulate that when these kinds of values are given, the precision is undefined. We also render them in .toString(); options are ignored in these cases (so the attempt to render, say, Infinity with 4 significant digits just returns "Infinity").

@jessealama jessealama linked an issue Sep 5, 2025 that may be closed by this pull request
Copy link
Member

@eemeli eemeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See line comments below for some details, but in general, this seems to be introducing a whole bunch of new logic that probably should not be new. Instead, we ought to copy or move text from ECMA-402 and the keep-trailing-zeros proposal to ECMA-262. That proposal is already effecting the same sort of parsing that's needed here by modifying ToIntlMathematicalValue.

We don't really want to define a new number parser here, as that runs a high risk of introducing a difference with the exisitng JS number parsers, so we ought to rely on pre-existing definitions as far as possible.

@jessealama
Copy link
Collaborator Author

jessealama commented Sep 9, 2025

See line comments below for some details, but in general, this seems to be introducing a whole bunch of new logic that probably should not be new. Instead, we ought to copy or move text from ECMA-402 and the keep-trailing-zeros proposal to ECMA-262. That proposal is already effecting the same sort of parsing that's needed here by modifying ToIntlMathematicalValue.

We don't really want to define a new number parser here, as that runs a high risk of introducing a difference with the exisitng JS number parsers, so we ought to rely on pre-existing definitions as far as possible.

I've taken a look -- indeed, we can reuse some 402 stuff, in particular the string parsing work already done in the StringIntlMV syntax-directed operation. I've used that now; the diff is now smaller. Can you take another look? I guess we should be able to refer to keep-trailing-zero's preservation of precision, too. To make things clean, I'd like to refer to a keep-trailing-zero biblio. Can you generate one?

@jessealama jessealama requested a review from eemeli September 9, 2025 14:41
@jessealama jessealama requested a review from eemeli September 10, 2025 09:42
Copy link
Member

@eemeli eemeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to merge; we'll still need to iterate on it, but that doesn't need to all happen in this PR.

I still think that the structure I proposed in #57 (comment) would be clearer, but that's just an editorial concern.

@jessealama jessealama merged commit a676bee into main Sep 11, 2025
2 checks passed
@jessealama jessealama deleted the 50-support-for-infinity branch September 11, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Infinity
2 participants