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;
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);
488 ret = write (fd, s,
vec_len (s));
500 u8 digit_buffer[128];
501 u8 *d = digit_buffer +
sizeof (digit_buffer);
511 number &= ((
u64) 1 << options->
n_bits) - 1;
513 base = options->
base;
520 if (r < 10 + 26 + 26)
524 else if (r < 10 + 26)
527 c =
'A' + (r - 10 - 26);
530 && base <= 10 + 26 && c >=
'a' && c <=
'z')
546 vec_add (s, d, digit_buffer +
sizeof (digit_buffer) - d);
552 #define f64_down(f,sign,expon,fraction) \ 554 union { u64 u; f64 f; } _f64_down_tmp; \ 555 _f64_down_tmp.f = (f); \ 556 (sign) = (_f64_down_tmp.u >> 63); \ 557 (expon) = ((_f64_down_tmp.u >> 52) & 0x7ff) - 1023; \ 558 (fraction) = ((_f64_down_tmp.u << 12) >> 12) | ((u64) 1 << 52); \ 571 tmp.u = (
u64) ((sign) != 0) << 63;
578 tmp.u |= (
u64) expon << 52;
580 tmp.u |= fraction & (((
u64) 1 << 52) - 1);
589 static int n_bits = 0;
605 return f64_up (0, base2_expon - n_bits, 0);
614 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
624 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
639 word expon2, expon10;
644 f64_down (x, sign, expon2, fraction);
648 expon2 * .301029995663981195213738894724493 ;
674 *expon_return = expon10;
697 word sign, expon, n_fraction_done, added_decimal_point;
702 if (n_fraction_digits == ~0)
703 n_fraction_digits = 7;
706 added_decimal_point = 0;
725 return format (s,
"%cNaN", sign ?
'-' :
'+');
729 return format (s,
"%cinfinity", sign ?
'-' :
'+');
734 if ((
word) - expon > (
word) n_fraction_digits
735 && (output_style ==
'f' || (output_style ==
'g')))
741 if (output_style ==
'f' 742 || (output_style ==
'g' && expon > -10 && expon < 10))
748 n_fraction_done =
clib_min (-(expon + 1), n_fraction_digits);
750 decimal_point = -n_fraction_done;
751 added_decimal_point = 1;
754 decimal_point = expon + 1;
780 if (decimal_point <= 0
781 && n_fraction_done + 1 == n_fraction_digits && digit < 9)
789 n_fraction_done += decimal_point < 0;
790 if (decimal_point <= 0 && n_fraction_done >= n_fraction_digits)
793 if (decimal_point == 0 && x != 0)
796 added_decimal_point = 1;
804 if (decimal_point > 0)
810 if (n_fraction_done < n_fraction_digits)
812 if (!added_decimal_point)
817 if (output_style ==
'e')
818 s =
format (s,
"e%wd", expon);
void os_puts(u8 *string, uword length, uword is_error)
Optimized string handling code, including c11-compliant "safe C library" variants.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
#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".