ferram4 / Ferram-Aerospace-Research

Aerodynamics model for Kerbal Space Program
Other
238 stars 131 forks source link

A more correct implementation of float to string (correct except for … #184

Closed Virindi-AC closed 7 years ago

Virindi-AC commented 7 years ago

…floating point inaccuracy). The old one had numerous issues, see https://github.com/ferram4/Ferram-Aerospace-Research/issues/183.

Fixes https://github.com/ferram4/Ferram-Aerospace-Research/issues/183

This implementation is not perfect, but it is a heck of a lot better than what it was. I included some simple test code that shows it is correct to within rounding error.

Note that writing a dtoa function is deceptively difficult. The original author of this code does not seem to have done much testing of his overly simplistic implementation (if any). If absolute correctness to CLR specs is desired, it may be a good idea to just accept the GC cost of an intermediate string. Otherwise, this new code should be "good enough".

ferram4 commented 7 years ago

LGTM