What's the status of to_chars/from_chars for floating-point types?
Jonathan Wakely
jwakely@redhat.com
Mon Jun 24 19:17:00 GMT 2019
On 24/06/19 21:13 +0300, Ruslan Kabatsayev wrote:
>Hi all,
>
>The C++17 functions to_chars and from_chars have been implemented for
>integer types quite a long time. Until recently, there were no
>implementations of their floating-point versions in major compilers.
>Now that STL has implemented these functions completely in MSVC, I
>wonder what their current status is in GCC.
I have an implementation of from_chars for float/double/long double.
Ed Smith-Rowland has said he's going to work on to_chars.
>So, is anyone actively working on it? If not, and no one is planning
>to begin soon, I'm considering giving it a try. But first I have some
>questions on it:
>
>* What's the expected form of this functionality â should it be a
>header-only implementation like the current one for integer types?
No, definitely not.
>* Could it use e.g. some dedicated functions in glibc (possibly
>implemented specially for libstdc++ â to take advantage of the
>existing codebase for printf), or maybe use libdouble-conversion for
>this (it can handle float and double types, not long double though)?
We can't rely on glibc because GCC supports lots of non-GNU targets.
>* Does it have to be fully self-contained in libstdc++, so that no
>external dependencies would be tolerated?
Yes. Any dependencies on an external library need to be handled by
adding the library to libstdc++.
>* Does it have to noticeably outperform printf, or would basically the
>same performance be good enough for a start?
If it doesn't outperform printf then it might as well just be
implemented by calling printf. So I think a non-trivial implementation
that fails to outperform printf is a waste of time.
The state of the art is https://github.com/ulfjack/ryu which also
needs a complete implementation of Dragon4 or Grisu3 for some edge
cases. And if I understand correctly, it doesn't support long double
(and GCC supports multiple different formats for long double,
depending on the target).
More information about the Libstdc++
mailing list