-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix out-of-bounds when converting from FixedDecimal to PluralOperands #290
Comments
Perhaps `Try` -> TryFrom` is all that is needed.
As an optimization, FixedDecimal could provide a flag that is set if any of
its components would overflow u64.
Another possible option, is that in the context of plural operands, not all
digits are actually significant. Perhaps we could make do by keeping in
PluralOperands only those digits that actually matter for plural formation.
For example, in Serbian 12345689110 and 110 are equivalent as far as
plurality is concerned.
…On Fri, Oct 2, 2020 at 3:04 PM Shane F. Carr ***@***.***> wrote:
FixedDecimal support numbers that are very large or very small. However,
PluralOperands only supports numbers with integer and fraction parts that
fit inside a u64. Discuss how to resolve cases when the FixedDecimal is
larger than what the PluralOperands can support.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#290>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB4GMBHPZG6H54GAV7GF3DSIZE7PANCNFSM4SCGJVAA>
.
|
I lean toward saying that we just throw away digits that are out of bounds. We could cap the number of digits at 18 integer and 18 fraction or something like that. |
In stdlib those are usually having lossy in the name. I'd suggest tryfrom and lossy and or panicking |
It's technically lossy, but for all real situations, keeping 18 digits on both side of the decimal separator is far more than enough to run plural rules. Panicking is definitely not the right behavior. I'm not a fan of TryFrom because this is a hot code path. I suppose we could add TryFrom in addition to From (if that's allowed, given that TryFrom has a default implementation based on From). |
Sure, so then calling it It's the same as |
Do you suggest we do not implement |
Hmm, I'm torn. I see that clamping to 18 digits may be seen not as And I understand the convenience value of using My only hiccup is that I'd like us to be able to have a path forward if later we want to add a fallible version because in some scenario we need to handle the overflow differently. If having both, |
FWIW, I don't think this conversion is actually lossy: it does remove information of the original exact number, but that does not lose information about its plurality. It is a one-way transform: (By taking the least significant digits from both the integer and fractional part, we will probably remove any distinction between the "full" and "lossy" conversions.) |
I'm convincend. |
One other thought I had. We don't want overflowed PluralOperands to select At what point in the process do you think clients are intended to support |
As in MessageFormat variant matching? |
FixedDecimal support numbers that are very large or very small. However, PluralOperands only supports numbers with integer and fraction parts that fit inside a u64. Discuss how to resolve cases when the FixedDecimal is larger than what the PluralOperands can support.
The text was updated successfully, but these errors were encountered: