55 #ifdef CLIB_STANDALONE 56 #include <vppinfra/standalone_stdio.h> 103 l0 = i0 + fi->
width[0];
115 uword n_left = 0, n_right = 0;
128 n_right = n_left = n/2;
136 memset (s + i0, fi->
pad_char, n_left);
142 memset (s + l1, fi->
pad_char, n_right);
184 uword is_first_digit = 1;
187 for (i = 0; i < 2; i++)
189 if (c ==
'0' && i == 0 && is_first_digit)
193 fi.
width[
i] = va_arg(*va,
int);
196 while (c >=
'0' && c <=
'9') {
220 if (c ==
'l' && *f ==
'l')
236 .uppercase_digits = 0,
246 s =
format (s,
"**** CLIB unknown format `%%%c' ****", c);
274 if (c ==
'x' || c ==
'X')
282 number = va_arg (*va,
unsigned long long);
287 number = va_arg (*va,
long);
292 number = va_arg (*va,
word);
297 number = va_arg (*va,
int);
309 char * cstring = va_arg (*va,
char *);
317 else if (fi.
width[1] != 0)
320 len = strlen (cstring);
325 for (i = 0; i < len; i++)
326 vec_add1 (s, cstring[i] ==
'_' ?
' ' : cstring[i]);
335 u8 * v = va_arg (*va,
u8 *);
338 if (fi.
width[1] != 0)
347 case 'f':
case 'g':
case 'e':
351 va_arg (*va,
double),
358 typedef u8 * (user_func_t) (
u8 * s, va_list * args);
359 user_func_t * u = va_arg (*va, user_func_t *);
366 s =
justify (s, &fi, s_initial_len);
376 u8 * f = (
u8 *) fmt, * g;
424 ret = fwrite (s,
vec_len (s), 1, f);
460 ret = write (fd, s,
vec_len (s));
471 u8 digit_buffer[128];
472 u8 * d = digit_buffer +
sizeof (digit_buffer);
482 number &= ((
u64) 1 << options->
n_bits) - 1;
484 base = options->
base;
498 c =
'A' + (r - 10 - 26);
502 && c >=
'a' && c <=
'z')
518 vec_add (s, d, digit_buffer +
sizeof (digit_buffer) - d);
524 #define f64_down(f,sign,expon,fraction) \ 526 union { u64 u; f64 f; } _f64_down_tmp; \ 527 _f64_down_tmp.f = (f); \ 528 (sign) = (_f64_down_tmp.u >> 63); \ 529 (expon) = ((_f64_down_tmp.u >> 52) & 0x7ff) - 1023; \ 530 (fraction) = ((_f64_down_tmp.u << 12) >> 12) | ((u64) 1 << 52); \ 536 union {
u64 u;
f64 f; } tmp;
538 tmp.u = (
u64) ((sign) != 0) << 63;
545 tmp.u |= (
u64) expon << 52;
547 tmp.u |= fraction & (((
u64) 1 << 52) - 1);
555 static int n_bits = 0;
571 return f64_up (0, base2_expon - n_bits, 0);
579 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
589 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
603 word expon2, expon10;
608 f64_down (x, sign, expon2, fraction);
610 expon10 = .5 + expon2 * .301029995663981195213738894724493 ;
636 *expon_return = expon10;
656 uword n_fraction_digits,
660 word sign, expon, n_fraction_done, added_decimal_point;
665 if (n_fraction_digits == ~0)
666 n_fraction_digits = 7;
669 added_decimal_point = 0;
688 return format (s,
"%cinfinity", sign ?
'-' :
'+');
693 if ((
word) -expon > (
word) n_fraction_digits
694 && (output_style ==
'f' || (output_style ==
'g')))
700 if (output_style ==
'f' 701 || (output_style ==
'g' && expon > -10 && expon < 10))
707 n_fraction_done =
clib_min (-(expon + 1), n_fraction_digits);
709 decimal_point = -n_fraction_done;
710 added_decimal_point = 1;
713 decimal_point = expon + 1;
739 if (decimal_point <= 0
740 && n_fraction_done + 1 == n_fraction_digits
749 n_fraction_done += decimal_point < 0;
750 if (decimal_point <= 0
751 && n_fraction_done >= n_fraction_digits)
754 if (decimal_point == 0 && x != 0)
757 added_decimal_point = 1;
765 if (decimal_point > 0)
771 if (n_fraction_done < n_fraction_digits)
773 if (! added_decimal_point)
778 if (output_style ==
'e')
779 s =
format (s,
"e%wd", expon);
sll srl srl sll sra u16x4 i
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...
static uword pointer_to_uword(const void *p)
#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).
#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".