Eric Blake wrote:
> According to Bruno Haible on 4/11/2008 4:43 AM:
> |   1) for float to decimal conversion, think of snprintf (NULL, "%Le", x)
> |      or snprintf (NULL, "%Lf", x)
> |
> | At least in the first case, I don't see how the number of output bytes could
> | be determined without doing the actual conversion.
> 
> True, but in the first case, the maximum number of significant digits is
> known in advance, so you can still use a fixed-size stack-allocated buffer
> to do the work.

It also depends on the exponent. And with 'long double's you can have up to
32-bit exponents. In order to determine how
   9.9999999999999999999999999999999999999999999e+3000000
rounds you need memory of size  3000000*log(10)/(8*log(2)). The only way to
allocate such an amount of memory inside snprintf is through malloc.

Bruno



Reply via email to