/* Determine the buffer size needed for the various * floating-point formats. * * The basic possibilities are: * * <---P---> * %f 1111111.123456789 * %e 1.111111123e+06 * %a 0x1.0f4471f9bp+20 * %g 1111111.12 * %g 1.11111112e+15 * * where P is the value of the precision in the format, or 6 * if not specified. Note the two possible output formats of * %g; in both cases the number of significant digits is <= * precision. * * For most of the format types the maximum buffer size needed * is precision, plus: any leading 1 or 0x1, the radix * point, and an exponent. The difficult one is %f: for a * large positive exponent it can have many leading digits, * which needs to be calculated specially. Also %a is slightly * different in that in the absence of a specified precision, * it uses as many digits as necessary to distinguish * different values. * * First, here are the constant bits. For ease of calculation * we over-estimate the needed buffer size, for example by * assuming all formats have an exponent and a leading 0x1. * * Also for production use, add a little extra overhead for * safety's sake. Under debugging don't, as it means we're * more likely to quickly spot issues during development. */ float_need = 1 /* possible unary minus */ + 4 /* "0x1" plus very unlikely carry */ + 1 /* default radix point '.' */ + 2 /* "e-", "p+" etc */ + 6 /* exponent: up to 16383 (quad fp) */ #ifndef DEBUGGING + 20 /* safety net */ #endif + 1; /* \0 */