18#define _DBL_SIGN(bytes) (((unsigned)bytes[7] & 0x80) >> 7)
19#define _DBL_DEC(bytes) ((_DBL_EXP(bytes) > 0) ? 1 : 0)
20#define _DBL_EXP(bytes) ((((unsigned)bytes[7] & 0x7f) << 4) | (((unsigned)bytes[6] & 0xf0) >> 4))
22#define _DBL_MANT_START(bytes) (bytes + 6)
24#if __LDBL_MANT_DIG__ == 64
27#define _LDBL_SIGN(bytes) (((unsigned)bytes[9] & 0x80) >> 7)
28#define _LDBL_DEC(bytes) (((unsigned)bytes[7] & 0x80) >> 7)
29#define _LDBL_EXP(bytes) ((((unsigned)bytes[9] & 0x7f) << 8) | (unsigned)bytes[8])
30#define _LDBL_BIAS 16383
31#define _LDBL_MANT_START(bytes) (bytes + 7)
33#elif __LDBL_MANT_DIG__ == 113
36#define _LDBL_SIGN(bytes) (((unsigned)bytes[15] & 0x80) >> 7)
37#define _LDBL_DEC(bytes) ((_LDBL_EXP(bytes) > 0) ? 1 : 0)
38#define _LDBL_EXP(bytes) ((((unsigned)bytes[15] & 0x7f) << 8) | (unsigned)bytes[14])
39#define _LDBL_BIAS 16383
40#define _LDBL_MANT_START(bytes) (bytes + 13)
45#define _LDBL_SIGN(bytes) (((unsigned)bytes[7] & 0x80) >> 7)
46#define _LDBL_DEC(bytes) ((_LDBL_EXP(bytes) > 0) ? 1 : 0)
47#define _LDBL_EXP(bytes) ((((unsigned)bytes[7] & 0x7f) << 4) | (((unsigned)bytes[6] & 0xf0) >> 4))
48#define _LDBL_BIAS 1023
49#define _LDBL_MANT_START(bytes) (bytes + 6)
53#define _PRINT_PUT(ctx, x) \
56 if ((ctx)->totalChars < (ctx)->maxChars) \
58 if ((ctx)->stream != NULL) \
60 putc(character, (ctx)->stream); \
64 (ctx)->buffer[(ctx)->totalChars] = character; \
67 ++((ctx)->totalChars); \
70#define _PRINT_PUT(ctx, x) \
73 if ((ctx)->totalChars < (ctx)->maxChars) \
75 if ((ctx)->buffer != NULL) \
77 (ctx)->buffer[(ctx)->totalChars] = character; \
80 ++((ctx)->totalChars); \
91 unsigned char mantissa[32] = {0};
101 int index_offset = 0;
110 excess_bits = (mant_dig - 1) % 8;
114 value = *mant & ((1 << excess_bits) - 1);
116 if (excess_bits >= 4)
118 mantissa[1] = value & 0x0f;
127 mantissa[0] = (dec << excess_bits) | (value & ((1 << excess_bits) - 1));
135 while (m < ((mant_dig + 3) / 4 - 1))
137 value = *(mant - ((m / 2) + index_offset));
138 mantissa[++m] = (value & 0xf0) >> 4;
139 mantissa[++m] = (value & 0x0f);
143 while (m > 0 && mantissa[m] == 0)
153 if ((m == 0 && dec == 0) ||
exp == 0)
178 for (e = 1;
exp > 0; ++e)
181 exponent[e] = digit_chars[d.
rem];
195 if ((mantissa[i + 1] > 8) || ((mantissa[i + 1] == 8) && ((m >= i + 2) || (mantissa[i] % 2))))
197 while ((++mantissa[i]) > 0xf)
245 for (i = 1; i <= m; ++i)
250 while ((
int)i <= ctx->precision)
259 for (i = e - 1; i > 0; --i)
335 unsigned char bytes[
sizeof(double)];
337 memcpy(bytes, &value,
sizeof(
double));
340 if (
exp == __DBL_MAX_EXP__)
351 unsigned char bytes[
sizeof(
long double)];
353 memcpy(bytes, &value,
sizeof(
long double));
356 if (
exp == __LDBL_MAX_EXP__)
370 char preface[3] =
"\0";
381 preface[preidx++] =
'0';
392 preface[preidx++] =
'-';
399 preface[preidx++] =
'+';
405 preface[preidx++] =
' ';
431 if (ctx->
width > characters)
435 for (i = 0; i < ctx->
width - characters; ++i)
446 while (preface[preidx] !=
'\0')
453 while (prec_pads-- > 0)
563 const char* orig_spec = spec;
565 if (*(++spec) ==
'%')
677 ctx->
flags &= ~FORMAT_ZERO;
854 long double value =
va_arg(ctx->
arg,
long double);
#define NULL
Pointer error value.
_PUBLIC imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom)
__UINTMAX_TYPE__ uintmax_t
static void _print_double(double value, _format_ctx_t *ctx)
static void _print_fp(int sign, int exp, int dec, unsigned char const *mant, size_t mant_dig, _format_ctx_t *ctx)
static void _print_string(const char *s, _format_ctx_t *ctx)
static void _print_hexa(int sign, int exp, int dec, unsigned char const *mant, size_t mant_dig, _format_ctx_t *ctx)
#define _LDBL_SIGN(bytes)
#define _DBL_MANT_START(bytes)
#define _PRINT_PUT(ctx, x)
const char * _print(const char *spec, _format_ctx_t *ctx)
static void _print_ldouble(long double value, _format_ctx_t *ctx)
static void _print_integer(imaxdiv_t div, _format_ctx_t *ctx)
static void _int_format(intmax_t value, _format_ctx_t *ctx)
#define _LDBL_MANT_START(bytes)
__PTRDIFF_TYPE__ ptrdiff_t
__UINTPTR_TYPE__ uintptr_t
_PUBLIC div_t div(int numer, int denom)
#define strtol(nptr, endptr, base)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)