From 872cf03f26c2801ae6c3008ce5fa0d7856f5f85d Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 14 Dec 2025 18:10:13 +0100 Subject: libc: implement err/warn functions --- lib/libc/stdio/vfprintf.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'lib/libc/stdio/vfprintf.c') diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 126c1193..06609046 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -1,13 +1,40 @@ -#include // for isdigit -#include // for EINVAL, errno -#include // for frexp, isinf, isnan -#include // for va_arg -#include // for NULL, ptrdiff_t +#include // for isdigit +#include // for EINVAL, errno +#include // for isinf, isnan +#include // for va_arg +#include // for NULL, ptrdiff_t +#include #include // for uintptr_t, intmax_t, uintmax_t #include // for fwrite, fputc, vfprintf, FILE, va_list #include // for memmove, strlcpy, strlen #include // for size_t, ssize_t +static double __frexp(double x, int *e) +{ + union { + double d; + uint64_t i; + } y = { x }; + uint64_t ee = y.i >> 52 & 0x7ff; + + if (!ee) { + if (x) { + x = __frexp(x * 0x1p64, e); + *e -= 64; + } else + *e = 0; + return x; + } + if (ee == 0x7ff) { + return x; + } + + *e = (int)ee - 0x3fe; + y.i &= 0x800fffffffffffffull; + y.i |= 0x3fe0000000000000ull; + return y.d; +} + extern char *dtoa(double, int mode, int ndigits, int *decpt, int *sign, char **rve); extern void freedtoa(char *s); @@ -615,7 +642,7 @@ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) } int exp; - double mant = frexp(val, &exp); + double mant = __frexp(val, &exp); mant *= 2.0; exp--; -- cgit v1.2.3