2 * fltpr.c - print floating point numbers
9 #include "../stdio/loc_incl.h"
13 _pfloat(long double r
, register char *s
, int n
, int flags
)
19 s1
= _fcvt(r
, n
, &dp
, &sign
);
22 else if (flags
& FL_SIGN
)
24 else if (flags
& FL_SPACE
)
30 if (*s1
) *s
++ = *s1
++;
32 if (((i
=n
) > 0) || (flags
& FL_ALT
))
40 if (*s1
) *s
++ = *s1
++;
46 _pscien(long double r
, register char *s
, int n
, int flags
)
51 s1
= _ecvt(r
, n
+ 1, &dp
, &sign
);
54 else if (flags
& FL_SIGN
)
56 else if (flags
& FL_SPACE
)
60 if ((n
> 0) || (flags
& FL_ALT
))
63 if (*s1
) *s
++ = *s1
++;
68 *s
++ = '-' ; dp
= -dp
;
73 *s
++ = '0' + (dp
/ 100);
81 #define NDIGINEXP(exp) (((exp) >= 100 || (exp) <= -100) ? 3 : 2)
83 #define USE_EXP(exp, ndigits) (((exp) < LOW_EXP + 1) || (exp >= ndigits + 1))
86 _gcvt(long double value
, int ndigit
, char *s
, int flags
)
89 register char *s1
, *s2
;
91 register int nndigit
= ndigit
;
93 s1
= _ecvt(value
, ndigit
, &dp
, &sign
);
95 if (sign
) *s2
++ = '-';
96 else if (flags
& FL_SIGN
)
98 else if (flags
& FL_SPACE
)
101 if (!(flags
& FL_ALT
))
102 for (i
= nndigit
- 1; i
> 0 && s1
[i
] == '0'; i
--)
105 if (USE_EXP(dp
,ndigit
)) {
109 if ((nndigit
> 1) || (flags
& FL_ALT
)) *s2
++ = '.';
110 while (--nndigit
> 0) *s2
++ = *s1
++;
119 for (i
= NDIGINEXP(dp
); i
> 0; i
--) {
120 *--s2
= dp
% 10 + '0';
128 /* otherwise the whole number is 0 */
137 for (i
= 1; i
<= nndigit
; i
++) {
139 if (i
== dp
) *s2
++ = '.';
142 while (i
++ <= dp
) *s2
++ = '0';
145 if ((s2
[-1]=='.') && !(flags
& FL_ALT
)) s2
--;
151 _f_print(va_list *ap
, int flags
, char *s
, char c
, int precision
)
153 register char *old_s
= s
;
156 if (flags
& FL_LONGDOUBLE
) ld_val
= va_arg(*ap
, long double);
157 else ld_val
= (long double) va_arg(*ap
, double);
161 s
= _pfloat(ld_val
, s
, precision
, flags
);
165 s
= _pscien(ld_val
, s
, precision
, flags
);
169 s
= _gcvt(ld_val
, precision
, s
, flags
);
173 if ( c
== 'E' || c
== 'G') {
174 while (*old_s
&& *old_s
!= 'e') old_s
++;
175 if (*old_s
== 'e') *old_s
= 'E';
183 #include "../ansi/ext_fmt.h"
185 void _str_ext_cvt(const char *s
, char **ss
, struct EXTEND
*e
);
186 double _ext_dbl_cvt(struct EXTEND
*e
);
189 strtod(const char *p
, char **pp
)
193 _str_ext_cvt(p
, pp
, &e
);
194 return _ext_dbl_cvt(&e
);