1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:08:13 +00:00

LibJS+LibUnicode: Fix computation of compact pattern exponents

The compact scale of each formatting rule was precomputed in commit:
be69eae651

Using the formula: compact scale = magnitude - pattern scale

This computation was off-by-one.

For example, consider the format key "10000-count-one", which maps to
"00 thousand" in en-US. What we are really after is the exponent that
best represents the string "thousand" for values greater than 10000
and less than 100000 (the next format key). We were previously doing:

    log10(10000) - "00 thousand".count("0") = 2

Which clearly isn't what we want. Instead, if we do:

    log10(10000) + 1 - "00 thousand".count("0") = 3

We get the correct exponent for each format key for each locale.

This commit also renames the generated variable from "compact_scale" to
"exponent" to match the terminology used in ECMA-402.
This commit is contained in:
Timothy Flynn 2021-11-15 07:56:20 -05:00 committed by Linus Groh
parent 48d5684780
commit 1f546476d5
3 changed files with 23 additions and 23 deletions

View file

@ -117,7 +117,7 @@ struct NumberFormat {
};
u8 magnitude { 0 };
u8 compact_scale { 0 };
u8 exponent { 0 };
Plurality plurality { Plurality::Other };
StringView zero_format {};
StringView positive_format {};