Commit graph

28 commits

Author SHA1 Message Date
Timothy Flynn
887dac0929 LibJS: Handle NumberFormat's [[UseGrouping]] option for "true" / "false"
This is a normative change to the Intl NumberFormat V3 spec. See:
https://github.com/tc39/proposal-intl-numberformat-v3/commit/4751da5
2022-09-18 09:45:40 -04:00
Timothy Flynn
fd7d97fba5 LibJS: Allow out-of-order number ranges to be formatted
This is a normative change to the Intl NumberFormat V3 spec:
https://github.com/tc39/proposal-intl-numberformat-v3/commit/0c3d849
2022-07-26 10:46:08 -07:00
Timothy Flynn
e9e187d15c LibJS: Implement Intl.NumberFormat.prototype.formatRangeToParts 2022-07-20 22:30:16 +01:00
Timothy Flynn
b4a772cde2 LibJS: Implement Intl.NumberFormat.prototype.formatRange 2022-07-20 22:30:16 +01:00
Timothy Flynn
4b415a23c1 LibJS: Implement Intl.NumberFormat V3's [[RoundingIncrement]] changes 2022-07-18 23:37:31 +01:00
Timothy Flynn
8ee485c350 LibJS: Implement Intl.NumberFormat V3's [[RoundingMode]] changes 2022-07-18 23:37:31 +01:00
Timothy Flynn
37ab7cc694 LibJS: Implement Intl.NumberFormat V3's [[TrailingZeroDisplay]] changes 2022-07-18 08:51:07 +01:00
Timothy Flynn
bb9a44cd50 LibJS: Implement Intl.NumberFormat V3's [[RoundingPriority]] changes 2022-07-18 08:51:07 +01:00
Timothy Flynn
9e50f25ac4 LibJS: Prevent i64 overflow when computing large NumberFormat exponents
The largest exponents we compute are on the order of 10^21 (governed by
the maximumSignificantDigits option, which has a max value of 21). That
is too large to fit into the i64 we were using when multiplying this
exponent by the value to be formatted.

Instead, split up the logic to multiply that value by this exponent
based on the value's underlying type:

Number: Do not cast the result of pow() to an i64, and perform the
follow-up multiplication with doubles.

BigInt: Do not use pow(). Instead, compute the exponent as a BigInt
from the start, then perform the follow-up multiplication with that
BigInt.
2022-07-18 08:51:07 +01:00
Timothy Flynn
aafcdc4c72 LibJS: Allow specifying keyword values not directly defined for a locale
For example, consider the locales "en-u-nu-fullwide" or "en-u-nu-arab".
The CLDR only declares the "latn" numbering system for the "en" locale,
thus ResolveLocale would change the locale to "en-u-nu-latn". This patch
allows using non-latn numbering systems digits.
2022-07-15 12:31:43 +02:00
Timothy Flynn
cff2d631da LibJS: Implement Intl.NumberFormat V3's [[SignDisplay]] changes
Intl.NumberFormat V3 adds a "negative" option for [[SignDisplay]] to
only use the locale's signed pattern for negative numbers.
2022-07-13 19:22:26 +01:00
Timothy Flynn
733192089f LibJS: Implement Intl.NumberFormat V3's [[UseGrouping]] changes
In the main spec, [[UseGrouping]] can be true or false. In V3, it may be
one of:

    auto: Respect the per-locale preference for grouping.

    always: Ignore per-locale preference for grouping and always insert
    the grouping separator (note: true is now an alias for always).

    min2: Ignore per-locale preference for grouping and only insert the
    grouping separator if the primary group has at least 2 digits.

    false: Ignore per-locale preference for grouping and never insert
    the grouping separator.
2022-07-13 19:22:26 +01:00
Timothy Flynn
33698b9615 LibJS+js: Parse new constructor options from Intl.NumberFormat V3
This contains minimal changes to parse newly added and modified options
from the Intl.NumberFormat V3 proposal, while maintaining main spec
behavior in Intl.NumberFormat.prototype.format. The parsed options are
reflected only in Intl.NumberFormat.prototype.resolvedOptions and the js
REPL.
2022-07-13 19:22:26 +01:00
Timothy Flynn
d6e926e5b1 LibJS: Support BigInt number formatting with Intl.NumberFormat 2022-01-30 20:05:27 +00:00
Timothy Flynn
cf92bc42a2 LibJS: Respect per-locale minimum grouping digits when number formatting 2022-01-27 20:30:52 +00:00
Timothy Flynn
a1d5849e67 LibJS: Implement unit number formatting 2021-11-16 23:14:09 +00:00
Timothy Flynn
99c15741ba LibJS: Conditionally ignore [[UseGrouping]] in compact notation 2021-11-16 00:56:55 +00:00
Timothy Flynn
fdae323401 LibJS: Implement compact formatting for Intl.NumberFormat 2021-11-16 00:56:55 +00:00
Timothy Flynn
4d79ab6866 LibJS: Implement engineering and scientific number formatting 2021-11-14 17:00:35 +00:00
Timothy Flynn
15c5fbd9e9 LibJS: Implement number grouping for Intl.NumberFormat
For example, in en-US, the number 123456 should be formatted as the
string "123,456". In en-IN, it should be formatted as "1,23,456".
2021-11-14 10:35:19 +00:00
Timothy Flynn
3450def494 LibJS: Implement Intl.NumberFormat.prototype.formatToParts 2021-11-13 19:01:25 +00:00
Timothy Flynn
40973814e9 LibJS: Throw an exception in NumberFormat.prototype.format for BigInts
Rather than crashing in the call to as_double(), throw an exception for
now.
2021-11-13 19:01:25 +00:00
Timothy Flynn
a701ed52fc LibJS+LibUnicode: Fully implement currency number formatting
Currencies are a bit strange; the layout of currency data in the CLDR is
not particularly compatible with what ECMA-402 expects. For example, the
currency format in the "en" and "ar" locales for the Latin script are:

    en: "¤#,##0.00"
    ar: "¤\u00A0#,##0.00"

Note how the "ar" locale has a non-breaking space after the currency
symbol (¤), but "en" does not. This does not mean that this space will
appear in the "ar"-formatted string, nor does it mean that a space won't
appear in the "en"-formatted string. This is a runtime decision based on
the currency display chosen by the user ("$" vs. "USD" vs. "US dollar")
and other rules in the Unicode TR-35 spec.

ECMA-402 shies away from the nuances here with "implementation-defined"
steps. LibUnicode will store the data parsed from the CLDR however it is
presented; making decisions about spacing, etc. will occur at runtime
based on user input.
2021-11-13 11:52:45 +00:00
Timothy Flynn
89523f70cf LibJS: Begin implementing Intl.NumberFormat.prototype.format
There is quite a lot to be done here so this is just a first pass at
number formatting. Decimal and percent formatting are mostly working,
but only for standard and compact notation (engineering and scientific
notation are not implemented here). Currency formatting is parsed, but
there is more work to be done to handle e.g. using symbols instead of
currency codes ("$" instead of "USD"), and putting spaces around the
currency symbol ("USD 2.00" instead of "USD2.00").
2021-11-12 09:17:08 +00:00
Timothy Flynn
9b5696fee7 LibJS: Implement Intl.NumberFormat.prototype.resolvedOptions 2021-09-11 11:05:50 +01:00
Timothy Flynn
071e193d92 LibJS: Implement Intl.NumberFormat.supportedLocalesOf 2021-09-11 11:05:50 +01:00
Timothy Flynn
e42ba7f748 LibJS: Implement the Intl.NumberFormat constructor 2021-09-11 11:05:50 +01:00
Timothy Flynn
07f12b108b LibJS: Implement a nearly empty Intl.NumberFormat object
This adds plumbing for the Intl.NumberFormat object, constructor, and
prototype.
2021-09-11 11:05:50 +01:00