icu4x
icu4x copied to clipboard
FloatPrecision::Floating is a bit of a misnomer
FloatPrecision::Floating is the "shortest round-trippable" representation of the f64. Calling it "floating" is a random term that isn't really accurate. What is a better name for the mode?
We may also wish to reserve a name in this enum for a full-precision floating point conversion to avoid the double-rounding issue.
@eggrobin
Discuss with:
- @sffc
- @eggrobin
- @echeran
@echeran, @eggrobin, can you contribute items to the bikeshed?
- @eggrobin - Maybe "round-trip", based on existing usage in C# documentation: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#round-trip-format-specifier-r. I need to look at more sources.
RoundTripMax(why is it shortest round trippable and not largest roundtrippable?), elseRoundTripMinNoRoundingTruncatedLossless
The C++ standard uses shortest representation (see above), where above refers to a paragraph that reads:
The functions that take a floating-point value but not a precision parameter ensure that the string representation consists of the smallest number of characters such that there is at least one digit before the radix point (if present) and parsing the representation using the corresponding from_chars function recovers value exactly. [Note 1: This guarantee applies only if to_chars and from_chars are executed on the same implementation. — end note] If there are several such representations, the representation with the smallest difference from the floating-point argument value is chosen, resolving any remaining ties using rounding according to round_to_nearest.
The fact that they need that parenthetical hints at shortest not being specific enough. But maybe we could combine that with round-trip, something based on shortest round-tripping representation? (And then maybe dropping the head noun from that and playing with the grammar according to the local style.)
For context, the whole enum is
#[non_exhaustive]
pub enum FloatPrecision {
Integer,
Magnitude(i16),
SignificantDigits(i16),
Floating,
}
The Google C++ double_conversion library calls it ToShortest:
https://github.com/google/double-conversion/blob/15b7e306433dd899585f92758f7776a37a9c25ff/double-conversion/double-to-string.h#L240C8-L240C18
So in an effort to be short how about FloatPrecision::Shortest?
Do we have consensus on FloatPrecision::Shortest?
- [ ] @eggrobin
- [ ] @echeran
- [x] @jedel1043
Agreed on Shortest. Easy to remember and mostly similar to "shortest round trip".
- @eggrobin - "Shortest" is not very short; it will be quite long most of the time. What is special about it is that it round-trips.
- @younies - As a user, it isn't clear what "Shortest" means.
- @Manishearth - "ShortestRoundTrip" is probably the most accurate, but it is a bit long. I'm fine with it.
- @eggrobin - I would be okay with "RoundTrip", since people usually want the shortest representation when round-tripping.
- @younies - Lossless?
- @eggrobin - "Lossless" doesn't add to the clarity.
- @sffc - I'm okay with "RoundTrip" or "ShortestRoundTrip". I'm also okay with "Shortest" because I think it is strange enough to make people look at the docs.
- @Manishearth - I think "Shortest" is misleading.
- @eggrobin - A short name is never strange enough.
Proposal: RoundTrip
LGTM: @eggrobin @younies @Manishearth @sffc