On Mon, Oct 17, 2022 at 09:33:02PM +0000, Joseph Myers wrote: > > > And I/O etc. support is missing, not sure I'm able to handle that and if > > > it > > > is e.g. possible to keep that support out of libstdc++.so.6, because what > > > extended floating point types one has on a particular arch could change > > > over > > > time (I mean e.g. bfloat16_t support or float16_t support can be added > > > etc.). > > > > Yes, I think we can add the I/O functions as always_inline because all > > they're going to do is convert the argument to float, double, or long > > double and then call the existing overloads. There will be no new > > virtual functions. > > As with fma, note that doing conversions from strings to floating-point is > a case where doing the operation on float and then narrowing is > technically incorrect because double rounding can occur (the rounded float > result can be half way between two values of the narrower type, without > that being the exact mathematical result) but the operation should be > correctly rounding. It's fine to use float or double operations in the > other direction (floating-point to strings), of course.
That is true, but for istream and ostream that is what the standard requires. This is because there are required facets to be called and they are available just for float/double/long double and it would be an ABI change to allow more. For extended floating point wider than long double it is implementation defined what happens. And otherwise, there is [ Note: When the extended floating-point type has a floating-point conversion rank that is not equal to the rank of any standard floating-point type, then double rounding during the conversion can result in inaccurate results. from_chars can be used in situations where maximum accuracy is important. - end note ] As for <charconv>, I think we'll need to implement both directions, though perhaps the float16_t or bfloat16_t to_chars can be partly or fully implemented using the float to_chars. Jakub