55 #ifdef CLIB_STANDALONE 56 #include <vppinfra/standalone_stdio.h> 108 l0 = i0 + fi->
width[0];
120 uword n_left = 0, n_right = 0;
133 n_right = n_left = n / 2;
141 memset (s + i0, fi->
pad_char, n_left);
147 memset (s + l1, fi->
pad_char, n_right);
190 uword is_first_digit = 1;
193 for (i = 0; i < 2; i++)
195 if (c ==
'0' && i == 0 && is_first_digit)
200 fi.
width[
i] = va_arg (*va,
int);
205 while (c >=
'0' && c <=
'9')
230 if (c ==
'l' && *f ==
'l')
246 .uppercase_digits = 0,
257 s =
format (s,
"**** CLIB unknown format `%%%c' ****", c);
285 if (c ==
'x' || c ==
'X')
293 number = va_arg (*va,
unsigned long long);
298 number = va_arg (*va,
long);
303 number = va_arg (*va,
word);
308 number = va_arg (*va,
int);
320 char *cstring = va_arg (*va,
char *);
328 else if (fi.
width[1] != 0)
331 len = strlen (cstring);
336 for (i = 0; i < len; i++)
337 vec_add1 (s, cstring[i] ==
'_' ?
' ' : cstring[i]);
346 u8 *
v = va_arg (*va,
u8 *);
349 if (fi.
width[1] != 0)
369 typedef u8 *(user_func_t) (
u8 * s, va_list * args);
370 user_func_t *u = va_arg (*va, user_func_t *);
377 s =
justify (s, &fi, s_initial_len);
388 u8 *f = (
u8 *) fmt, *g;
438 ret = fwrite (s,
vec_len (s), 1, f);
476 ret = write (fd, s,
vec_len (s));
488 u8 digit_buffer[128];
489 u8 *d = digit_buffer +
sizeof (digit_buffer);
499 number &= ((
u64) 1 << options->
n_bits) - 1;
501 base = options->
base;
508 if (r < 10 + 26 + 26)
512 else if (r < 10 + 26)
515 c =
'A' + (r - 10 - 26);
518 && base <= 10 + 26 && c >=
'a' && c <=
'z')
534 vec_add (s, d, digit_buffer +
sizeof (digit_buffer) - d);
540 #define f64_down(f,sign,expon,fraction) \ 542 union { u64 u; f64 f; } _f64_down_tmp; \ 543 _f64_down_tmp.f = (f); \ 544 (sign) = (_f64_down_tmp.u >> 63); \ 545 (expon) = ((_f64_down_tmp.u >> 52) & 0x7ff) - 1023; \ 546 (fraction) = ((_f64_down_tmp.u << 12) >> 12) | ((u64) 1 << 52); \ 559 tmp.u = (
u64) ((sign) != 0) << 63;
566 tmp.u |= (
u64) expon << 52;
568 tmp.u |= fraction & (((
u64) 1 << 52) - 1);
577 static int n_bits = 0;
593 return f64_up (0, base2_expon - n_bits, 0);
602 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
612 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
627 word expon2, expon10;
632 f64_down (x, sign, expon2, fraction);
636 expon2 * .301029995663981195213738894724493 ;
662 *expon_return = expon10;
685 word sign, expon, n_fraction_done, added_decimal_point;
690 if (n_fraction_digits == ~0)
691 n_fraction_digits = 7;
694 added_decimal_point = 0;
713 return format (s,
"%cinfinity", sign ?
'-' :
'+');
718 if ((
word) - expon > (
word) n_fraction_digits
719 && (output_style ==
'f' || (output_style ==
'g')))
725 if (output_style ==
'f' 726 || (output_style ==
'g' && expon > -10 && expon < 10))
732 n_fraction_done =
clib_min (-(expon + 1), n_fraction_digits);
734 decimal_point = -n_fraction_done;
735 added_decimal_point = 1;
738 decimal_point = expon + 1;
764 if (decimal_point <= 0
765 && n_fraction_done + 1 == n_fraction_digits && digit < 9)
773 n_fraction_done += decimal_point < 0;
774 if (decimal_point <= 0 && n_fraction_done >= n_fraction_digits)
777 if (decimal_point == 0 && x != 0)
780 added_decimal_point = 1;
788 if (decimal_point > 0)
794 if (n_fraction_done < n_fraction_digits)
796 if (!added_decimal_point)
801 if (output_style ==
'e')
802 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".