diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-14 18:10:13 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-14 19:28:34 +0100 |
| commit | 872cf03f26c2801ae6c3008ce5fa0d7856f5f85d (patch) | |
| tree | 94809812b71ee286eb5b74c70e4d08fc4c8dc057 /lib/libc/stdio/vfprintf.c | |
| parent | ec769a83bde09c76bd6ad9ee7f391036dba5cd97 (diff) | |
libc: implement err/warn functions
Diffstat (limited to 'lib/libc/stdio/vfprintf.c')
| -rw-r--r-- | lib/libc/stdio/vfprintf.c | 39 |
1 files changed, 33 insertions, 6 deletions
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 <ctype.h> // for isdigit -#include <errno.h> // for EINVAL, errno -#include <math.h> // for frexp, isinf, isnan -#include <stdarg.h> // for va_arg -#include <stddef.h> // for NULL, ptrdiff_t +#include <ctype.h> // for isdigit +#include <errno.h> // for EINVAL, errno +#include <math.h> // for isinf, isnan +#include <stdarg.h> // for va_arg +#include <stddef.h> // for NULL, ptrdiff_t +#include <stdint.h> #include <stdint.h> // for uintptr_t, intmax_t, uintmax_t #include <stdio.h> // for fwrite, fputc, vfprintf, FILE, va_list #include <string.h> // for memmove, strlcpy, strlen #include <sys/types.h> // 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--; |
