icu4x
icu4x copied to clipboard
FixedDecimal `*ed` methods should be infallible
This function is misleading:
pub fn concatenated_end(self, other: FixedDecimal) -> Result<Self, FixedDecimal>
In the error case, it returns other, but it still throws away self. It should probably return a tuple containing both FixedDecimals. It makes it tempting to write code such as mantissa.concatenated_end(fraction).unwrap_or_else(|fd| fd), which is wrong because it promotes fraction when it should probably keep mantissa and throw away fraction.
I think we should delete this function since it is only sugar over concatenate_end, which is harder to use incorrectly.
For the datetime use case, I think it would be useful to have a FixedDecimal constructor that accepts usize, usize as the integer and fractional parts. Then we avoid this infallibility altogether.
For the datetime use case, I think it would be useful to have a
FixedDecimalconstructor that acceptsusize, usizeas the integer and fractional parts. Then we avoid this infallibility altogether.
I don't think it solves the overlap issue.
I think it does. It would use IntIterator::from(integer).chain(IntIterator::from(fractional)) and then shift the resulting FixedDecimal by fractional.log10().
Hmm, that's quite clever. How does it handle these cases though?
- Seconds = 123, Nanoseconds = 20 (needs to know that there are leading zeros: easy enough)
- Seconds = 123, Nanoseconds = 4444444444 (same problem as we currently have: overlapping fields)
I wouldn't be opposed to implementing a plus operator that just performs a sum.