948ee2c50ce9906ecc83adbddf2db8cc95660c69
3 * LICENSE: See COPYING in the top level directory
5 * FILE: lib/sdk/crt/stdlib/ecvt.c
6 * PROGRAMERS: Gregor Schneider (parts based on ecvtbuf.c by DJ Delorie)
10 #define NUMBER_EFMT 18 /* sign, dot, null, 15 for alignment */
16 _ecvt (double value
, int ndigits
, int *decpt
, int *sign
)
18 static char ecvtbuf
[DBL_MAX_10_EXP
+ 10];
21 s
= cvtbuf
= (char*)malloc(ndigits
+ NUMBER_EFMT
);
32 sprintf(cvtbuf
, "%-+.*E", ndigits
, value
);
33 /* Treat special values */
34 if (strncmp(s
, "NaN", 3) == 0)
36 memcpy(ecvtbuf
, s
, 4);
38 else if (strncmp(s
+ 1, "Inf", 3) == 0)
40 memcpy(ecvtbuf
, s
, 5);
50 /* Copy the first digit */
53 if (d
- ecvtbuf
< ndigits
)
62 /* Skip the decimal point */
67 /* Copy fractional digits */
68 while (*s
&& *s
!= 'E')
70 if (d
- ecvtbuf
< ndigits
)
79 /* Skip the exponent */
84 /* Set the decimal point to the exponent value plus the one digit we copied */
86 /* Handle special decimal point cases */
93 /* Need enhanced precision*/
94 char* tbuf
= (char*)malloc(NUMBER_EFMT
);
100 sprintf(tbuf
, "%-+.*E", ndigits
+ 2, value
);
107 /* Pad with zeroes */
108 while (d
- ecvtbuf
< ndigits
)