Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative: Split out BigInt formatting functions #318

Closed
wants to merge 2 commits into from

Conversation

littledan
Copy link
Member

@littledan littledan commented Jan 25, 2019

Two new methods are added to Intl.NumberFormat.prototype:

  • formatBigInt
  • formatBigIntToParts

The earlier format/formatToParts methods are reverted to
accept Number and not BigInt.

Replacement for #236


Closes #236

This patch brings Intl.NumberFormat support to BigInt, and
adds a BigInt.prototype.toLocaleString method based on it.

The design here is to include overloading between BigInt and Number
as arguments for the format and formatToParts methods based on
ToNumeric. This means that, for example, string arguments are
cast to Number, rather than BigInt. This design preserves
compatibility and consistency with operators like unary -

This definition permits options in the NumberFormat to force
decimal places, e.g., 1n formatting as 1.00000 if the minimum
fractional digits is 5. Alternative semantics would be to
throw an exception in this case.

For the algorithm text itself: the specification algorithms
ToRawPrecision and ToRawFixed are now used for both Numbers
and BigInts. Given the ECMAScript specification's use of implicit
coercisions between Numbers and mathematical values, I believe
that this is valid without any special changes; the phrasing
may change in the future [1].

ICU4C-based implementations of ECMAScript can use
LocalizedNumberFormatter::formatDecimal [2] or
unum_formatDecimal [3] to implement the algorithms in this patch.

[1] tc39/ecma262#1135
[2] http://icu-project.org/apiref/icu4c/classicu_1_1number_1_1LocalizedNumberFormatter.html#a29cd3d107b784496e19175ce0115f26f
[3] http://icu-project.org/apiref/icu4c/unum_8h.html#a59870a322f012dc1b9d99cf8a7b708f1

Closes tc39#218
Two new methods are added to Intl.NumberFormat.prototype:
- formatBigInt
- formatBigIntToParts

The earlier format/formatToParts methods are reverted to
accept Number and not BigInt.
@FrankYFTang
Copy link
Contributor

If this is a REPLACEMENT of #236 then should we close #236 ?

@leobalter
Copy link
Member

I edited the top post with the "Closes ..." hint so GH would auto close the referenced PR when this gets merged.

Should we wait to have a decision in the meeting?

@littledan
Copy link
Member Author

Yes, I would like to wait for a conclusion in TC39.

@sffc
Copy link
Contributor

sffc commented Mar 28, 2019

Is it safe to close this PR now that the committee agreed to move forward with the original idea, #236?

@littledan
Copy link
Member Author

@sffc Yes, closing per #318 (comment)

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.

4 participants