http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48602

--- Comment #41 from Thomas Henlich <thenlich at users dot sourceforge.net> 
2011-04-21 16:36:14 UTC ---
Actually it may be even simpler than that:

We already know how many significant digits (d) we want in the output string,
and at what digit to round. So we can write the digits of the significand into
a buffer (with Ew.d editing). All that would remain is to decide whether to
print the exponent or not (according to a simple integer comparison), otherwise
shift the decimal point to the right place (simple string operation).

E.g.


0.0995 with RU,G0.2
dtoa -> ".10", exponent=0
output -> ".10"

12345000 with RD,G0.4:
dtoa -> ".1234", exponent=8
output -> ".1234E+08" because exponent > d

12345678.95 with RD,G0.9:
dtoa -> ".123456789", exponent=8
output -> "123456789." because exponent < d

Reply via email to