unicode-org / icu4x

Solving i18n for client-side and resource-constrained environments.
https://icu4x.unicode.org
Other
1.36k stars 174 forks source link

The behaviour of the overflow in `multiply_pow10` #2297

Open younies opened 2 years ago

younies commented 2 years ago

when a user call multiply_pow10 in FixedDecimal and an overflow happen, what shall we do:

  1. Set the number to Zero
  2. cut from the number (for example: if the number is 12345 and the user called multiply_pow10 by i16::MAX -3, the resulted number will be 34500000000......
  3. Add an infinity field to FixedDecimal so that +Infinity and -Infinity can be represented, and use that value when overflowing
  4. Saturate to the theoretical maximum FixedDecimal value
sffc commented 1 year ago

Discuss with:

Optional:

sffc commented 1 year ago

Consensus: add Infinity and -Infinity to the FixedDecimal data model. Support it when reading from f32, f64, and strings (the string value is "Infinity" and "-Infinity"). Support infinity in FixedDecimalFormatter as a replacement for the # in the pattern, producing outputs such as "$∞K". When a FixedDecimal operation overflows into infinity, have a debug assertion.

LGTM: @younies @Manishearth @skius @eggrobin @sffc