58 #define FL_LONGLONG 0x100 60 #define FL_NEGATIVE FL_LONG 62 #define FL_ALTUPP FL_PLUS 63 #define FL_ALTHEX FL_SPACE 65 #define FL_FLTUPP FL_ALT 66 #define FL_FLTEXP FL_PREC 67 #define FL_FLTFIX FL_LONG 75 unsigned char buf[23];
128 if (c >=
'0' && c <=
'9') {
134 width = 10*width + c;
152 }
else if ((flags &
FL_LONG) && c ==
'l') {
158 }
while ((c = *fmt++) != 0);
163 if (c >=
'E' && c <=
'G') {
167 }
else if (c >=
'e' && c <=
'g') {
177 float value = va_arg(ap,
double);
185 }
else if (c ==
'f') {
187 }
else if (prec > 0) {
191 if ((flags &
FL_FLTFIX) && fabsf(value) > 9999999) {
192 flags = (flags & ~FL_FLTFIX) |
FL_FLTEXP;
195 if (flags & FL_FLTFIX) {
197 ndigs = prec < 60 ? prec + 1 : 60;
205 memset(buf, 0,
sizeof(buf));
206 exp =
ftoa_engine(value, (
char *)buf, vtype, ndigs);
217 if (vtype & (FTOA_NAN |
FTOA_INF)) {
218 ndigs = sign ? 4 : 3;
233 const char *p =
"inf";
234 if (vtype & FTOA_NAN)
236 while ((ndigs = *p) != 0) {
246 if (flags & FL_FLTFIX) {
251 if ((
signed char)ndigs < 1) {
253 }
else if (ndigs > 8) {
257 if (exp <= prec && exp >= -4) {
260 while (prec && buf[1+prec] ==
'0') {
263 if (flags & FL_FLTFIX) {
265 prec = prec > exp ? prec - exp : 0;
270 if (flags & FL_FLTFIX) {
271 n = (exp>0 ? exp+1 : 1);
281 width = width > n ? width - n : 0;
300 if (flags & FL_FLTFIX) {
302 n = exp > 0 ? exp : 0;
308 v = (n <= exp && n > exp - ndigs)
309 ? buf[exp - n + 1] :
'0';
310 if (--n < -prec || v == 0) {
317 || (buf[1] ==
'5' && !(vtype &
FTOA_CARRY)))) {
332 s->
write(buf[sign++]);
339 if (exp < 0 || (exp == 0 && (vtype &
FTOA_CARRY) != 0)) {
344 for (ndigs =
'0'; exp >= 10; exp -= 10)
362 buf[0] = va_arg (ap,
int);
368 pnt = va_arg (ap,
char *);
369 size = strnlen (pnt, (flags &
FL_PREC) ? prec : ~0);
377 while (size < width) {
385 if (width) width -= 1;
396 if (c ==
'd' || c ==
'i') {
398 int64_t
x = va_arg(ap,
long long);
406 long x = (flags &
FL_LONG) ? va_arg(ap,
long) : va_arg(ap,
int);
445 (
char *)buf, base) - (
char *)buf;
448 ? va_arg(ap,
unsigned long)
449 : va_arg(ap,
unsigned int),
450 (
char *)buf, base) - (
char *)buf;
477 if (buf[c-1] ==
'0') {
497 while (len < width) {
503 width = (len < width) ? width - len : 0;
505 if (flags & FL_ALT) {
511 unsigned char z =
' ';
char * ultoa_invert(uint32_t val, char *s, uint8_t base)
char * ulltoa_invert(uint64_t val, char *s, uint8_t base)
void print_vprintf(AP_HAL::BetterStream *s, const char *fmt, va_list ap)
int16_t ftoa_engine(float val, char *buf, uint8_t precision, uint8_t maxDecimals)
virtual size_t write(uint8_t)=0