8 #define DBL_MAX M_MAX_D
15 _ecvt(value
, ndigit
, decpt
, sign
)
17 int ndigit
, *decpt
, *sign
;
19 return cvt(value
, ndigit
, decpt
, sign
, 1);
23 _fcvt(value
, ndigit
, decpt
, sign
)
25 int ndigit
, *decpt
, *sign
;
27 return cvt(value
, ndigit
, decpt
, sign
, 0);
30 static struct powers_of_10
{
45 cvt(value
, ndigit
, decpt
, sign
, ecvtflag
)
47 int ndigit
, *decpt
, *sign
;
49 static char buf
[NDIGITS
+1];
50 register char *p
= buf
;
53 if (ndigit
< 0) ndigit
= 0;
54 if (ndigit
> NDIGITS
) ndigit
= NDIGITS
;
65 if (value
>= DBL_MAX
) {
69 register struct powers_of_10
*pp
= &p10
[0];
71 if (value
>= 10.0) do {
72 while (value
>= pp
->pval
) {
76 } while ((++pp
)->exp
> 0);
80 while (value
* pp
->pval
< 10.0) {
84 } while ((++pp
)->exp
> 0);
86 (*decpt
)++; /* because now value in [1.0, 10.0) */
89 /* for fcvt() we need ndigit digits behind the dot */
91 if (pe
> &buf
[NDIGITS
]) pe
= &buf
[NDIGITS
];
94 *p
++ = (int)value
+ '0';
95 value
= 10.0 * (value
- (int)value
);
99 *p
+= 5; /* round of at the end */
107 /* maybe add another digit at the end,
108 because the point was shifted right
110 if (pe
> buf
) *pe
= '0';