icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

FloatPrecision::Floating is a bit of a misnomer

Open sffc opened this issue 2 years ago • 7 comments

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

sffc avatar Jul 18 '23 16:07 sffc

Discuss with:

  • @sffc
  • @eggrobin
  • @echeran

sffc avatar Jul 20 '23 17:07 sffc

@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.

sffc avatar Nov 09 '23 23:11 sffc

  • RoundTripMax (why is it shortest round trippable and not largest roundtrippable?), else RoundTripMin
  • NoRounding
  • TruncatedLossless

echeran avatar Nov 10 '23 00:11 echeran

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.)

eggrobin avatar Nov 10 '23 00:11 eggrobin

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?

sffc avatar Dec 29 '23 05:12 sffc

Do we have consensus on FloatPrecision::Shortest?

  • [ ] @eggrobin
  • [ ] @echeran
  • [x] @jedel1043

sffc avatar Feb 12 '24 23:02 sffc

Agreed on Shortest. Easy to remember and mostly similar to "shortest round trip".

jedel1043 avatar Feb 12 '24 23:02 jedel1043

  • @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

sffc avatar Mar 07 '24 11:03 sffc