55 #ifdef CLIB_STANDALONE 56 #include <vppinfra/standalone_stdio.h> 109 l0 = i0 + fi->
width[0];
121 uword n_left = 0, n_right = 0;
134 n_right = n_left = n / 2;
142 memset (s + i0, fi->
pad_char, n_left);
148 memset (s + l1, fi->
pad_char, n_right);
191 uword is_first_digit = 1;
194 for (i = 0; i < 2; i++)
196 if (c ==
'0' && i == 0 && is_first_digit)
201 fi.
width[
i] = va_arg (*va,
int);
206 while (c >=
'0' && c <=
'9')
231 if (c ==
'l' && *f ==
'l')
247 .uppercase_digits = 0,
258 s =
format (s,
"**** CLIB unknown format `%%%c' ****", c);
286 if (c ==
'x' || c ==
'X')
294 number = va_arg (*va,
unsigned long long);
299 number = va_arg (*va,
long);
304 number = va_arg (*va,
word);
309 number = va_arg (*va,
int);
321 char *cstring = va_arg (*va,
char *);
329 else if (fi.
width[1] != 0)
332 len = strlen (cstring);
337 for (i = 0; i < len; i++)
338 vec_add1 (s, cstring[i] ==
'_' ?
' ' : cstring[i]);
347 u8 *
v = va_arg (*va,
u8 *);
350 if (fi.
width[1] != 0)
370 typedef u8 *(user_func_t) (
u8 * s, va_list * args);
371 user_func_t *u = va_arg (*va, user_func_t *);
378 s =
justify (s, &fi, s_initial_len);
389 const u8 *f = (
u8 *) fmt, *g;
439 ret = fwrite (s,
vec_len (s), 1, f);
477 ret = write (fd, s,
vec_len (s));
489 u8 digit_buffer[128];
490 u8 *d = digit_buffer +
sizeof (digit_buffer);
500 number &= ((
u64) 1 << options->
n_bits) - 1;
502 base = options->
base;
509 if (r < 10 + 26 + 26)
513 else if (r < 10 + 26)
516 c =
'A' + (r - 10 - 26);
519 && base <= 10 + 26 && c >=
'a' && c <=
'z')
535 vec_add (s, d, digit_buffer +
sizeof (digit_buffer) - d);
541 #define f64_down(f,sign,expon,fraction) \ 543 union { u64 u; f64 f; } _f64_down_tmp; \ 544 _f64_down_tmp.f = (f); \ 545 (sign) = (_f64_down_tmp.u >> 63); \ 546 (expon) = ((_f64_down_tmp.u >> 52) & 0x7ff) - 1023; \ 547 (fraction) = ((_f64_down_tmp.u << 12) >> 12) | ((u64) 1 << 52); \ 560 tmp.u = (
u64) ((sign) != 0) << 63;
567 tmp.u |= (
u64) expon << 52;
569 tmp.u |= fraction & (((
u64) 1 << 52) - 1);
578 static int n_bits = 0;
594 return f64_up (0, base2_expon - n_bits, 0);
603 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
613 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
628 word expon2, expon10;
633 f64_down (x, sign, expon2, fraction);
637 expon2 * .301029995663981195213738894724493 ;
663 *expon_return = expon10;
686 word sign, expon, n_fraction_done, added_decimal_point;
691 if (n_fraction_digits == ~0)
692 n_fraction_digits = 7;
695 added_decimal_point = 0;
714 return format (s,
"%cNaN", sign ?
'-' :
'+');
718 return format (s,
"%cinfinity", sign ?
'-' :
'+');
723 if ((
word) - expon > (
word) n_fraction_digits
724 && (output_style ==
'f' || (output_style ==
'g')))
730 if (output_style ==
'f' 731 || (output_style ==
'g' && expon > -10 && expon < 10))
737 n_fraction_done =
clib_min (-(expon + 1), n_fraction_digits);
739 decimal_point = -n_fraction_done;
740 added_decimal_point = 1;
743 decimal_point = expon + 1;
769 if (decimal_point <= 0
770 && n_fraction_done + 1 == n_fraction_digits && digit < 9)
778 n_fraction_done += decimal_point < 0;
779 if (decimal_point <= 0 && n_fraction_done >= n_fraction_digits)
782 if (decimal_point == 0 && x != 0)
785 added_decimal_point = 1;
793 if (decimal_point > 0)
799 if (n_fraction_done < n_fraction_digits)
801 if (!added_decimal_point)
806 if (output_style ==
'e')
807 s =
format (s,
"e%wd", expon);
void os_puts(u8 *string, uword length, uword is_error)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
#define vec_insert(V, N, M)
Insert N vector elements starting at element M, initialize new elements to zero (no header...
#define vec_free(V)
Free vector's memory (no header).
static uword pointer_to_uword(const void *p)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".