charconv icon indicating copy to clipboard operation
charconv copied to clipboard

constexpr floating-point from_chars and to_chars

Open leni536 opened this issue 9 months ago • 2 comments

I am working on the C++ proposal P3652 and I wonder if PRs for constexpr floating-point charconv functions would be well-received in this project. I contributed to the fast_float and dragonbox projects to make their implementations constexpr.

leni536 avatar Apr 08 '25 13:04 leni536

Yes, so long as they contain the proper compatibility macros to keep C++11 support in this library. I can review or answer questions, but you'll find a lot of it to be familiar since fast_float, dragonbox, and floff are the primary methods used internally. You'll also see Ryu which is used for long double and __float128. I know those can all be made constexpr pretty readily. The only thing that would not be easily constexpred is I rely on <quadmath.h> for some of __float128. The type functions are easy to replace, but I also use strtoflt128 which I believe uses Gay's method inside. I never felt like re-implementing it to break the dependency.

mborland avatar Apr 08 '25 13:04 mborland

Regarding strtoflt128, I recently ported musl's strtod implementation to constexpr from_chars here. It supports 128 bit long double, so adding __float128 would be fairly straightforward.

leni536 avatar Apr 08 '25 13:04 leni536