tc39 / proposal-intl-numberformat-v3

Additional features for Intl.NumberFormat to solve key pain points.
MIT License
53 stars 12 forks source link

Limit exponent of intl mathematical value #98

Closed sffc closed 1 year ago

sffc commented 2 years ago

In order to support implementations that limit the number of exponent digits or significant digits, we should put some limit on the intl mathematical values. Consider the ICU4X limits as a model.

sffc commented 2 years ago

My proposal is to limit the strings as follows:

  1. Maximum number of significant digits: 100
  2. Minimum exponent: -1000
  3. Maximum exponent: 1000

Semantics for overflow:

This is intended to be consistent with Number semantics, but with larger limits.

ljharb commented 2 years ago

Why would mathematical values have any limits? They're math values.

Constellation commented 2 years ago

@sffc Could you offer the background of this issue? My understanding is that ICU4C can have very large amount of exponent as a decimal by using string. What is the reason of not doing it in ICU4X too?

sffc commented 2 years ago

CC @FrankYFTang

The V8 implementation requires an intermediate type to represent the intl mathematical value because it is used for certain operations such as < ~and ==~ for the purposes of range formatting. There has been pushback to making it a string with unbounded length for both the mantissa and the exponent. There is a desire to use a more compact representation for one or both pieces.

The ICU4X intermediate representation, FixedDecimal, allows for values with up to u16::MAX significant digits and exponents ranging from i16::MIN to i16::MAX.

sffc commented 2 years ago

2022-05-19 discussion: https://github.com/tc39/ecma402/blob/master/meetings/notes-2022-05-19.md#limit-exponent-of-intl-mathematical-value-98

Conclusion: Proceed with adding a limit upon parsing the string. Internally we will still use a mathematical value; this is only on the string parsing step. The limit should be set in a way that is implementable to check.

sffc commented 2 years ago

@romulocintra Please see the meeting minutes. It looks like we agreed on +/- 10K.

sffc commented 1 year ago

@romulocintra Do you plan to write the spec for this? It would be nice to present it at this week's TC39 meeting so that we can have a clean Stage 4 in January.