Gnulib contains modules like dtoastr that accurately convert floating point
numbers to strings.  For the opposite direction of conversion, Gnulib
offers strtod replacements, but these refer to conversion routines of the
host systems and may lack the accuracy described in Clinger's well-known
paper [1] IIUC.
Wouldn't it make sense to include an accurate conversion algorithm in
Gnulib like [2] with the small improvement from [3]?  Maybe code from glibc
can be reused.

Let me also mention what I feel is an inconvenience of the standard C
library functions: they mix parsing/composing the strings with the actual
conversion routines.  Routines that take the sign, the (integer) mantissa,
and the exponent separately (or return them separately) are more
fundamental. They can help when the external string format is not the same
as C's.

Please excuse me if Gnulib already has this functionality.  In this case, I
have overlooked it.

Thanks,

Marc

--

[1] https://dl.acm.org/doi/pdf/10.1145/93548.93557
[2] https://arxiv.org/pdf/2101.11408
[3] https://onlinelibrary.wiley.com/doi/10.1002/spe.3198

Reply via email to