ecma402 icon indicating copy to clipboard operation
ecma402 copied to clipboard

Ambiguous minimumFractionDigits resolution

Open longlho opened this issue 11 months ago • 3 comments

In https://tc39.es/ecma402/#sec-setnfdigitoptions 23.a.iii the sequence to set mnfd is ambiguous when mxfd is undefined.

3. Let mxfd be ? Get(options, "maximumFractionDigits").
...
ii. Set mxfd to ? DefaultNumberOption(mxfd, 0, 100, undefined).
iii. If mnfd is undefined, set mnfd to min(mnfdDefault, mxfd).

At this point, mxfd can be undefined which makes the operation min(mnfdDefault, mxfd) ambiguous. How should I handle this case?

Ref: https://github.com/formatjs/formatjs/issues/4678

longlho avatar Dec 09 '24 03:12 longlho

If mnfd is undefined, then mxfd is guaranteed to be non-undefined, because if both are undefined, then hasFd is set to false and step 23 isn't entered.

anba avatar Dec 09 '24 10:12 anba

Ah yeah you're right. Would it hurt to assert at that step?

longlho avatar Dec 09 '24 14:12 longlho

Right; hasFd means that either mnfd or mxfd is not undefined, so mnfd is undefined implies mxfd is not undefined and vice versa.

I'd be open to a comment or an assertion. If an assertion is used, we should add assertions throughout SetNumberFormatDigitOptions. I think I lean toward a comment in this case.

sffc avatar Dec 09 '24 16:12 sffc