Support proper %g, %f, and %a float formatting

See #61
See #104
This commit is contained in:
Justine Tunney
2021-03-05 10:31:16 -08:00
parent e26bdbec52
commit f064183646
48 changed files with 1034 additions and 921 deletions

25
libc/stdio/dtoa.c Normal file
View File

@ -0,0 +1,25 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2021 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/fmt/fmts.h"
#include "third_party/gdtoa/gdtoa.h"
char *__fmt_dtoa(double d0, int mode, int ndigits, int *decpt, int *sign,
char **rve) {
return dtoa(d0, mode, ndigits, decpt, sign, rve);
}

View File

@ -58,7 +58,7 @@
* This means it implies the quoting modifier, wraps the value with
* {,u,L}['"] quotes, displays NULL as "NULL" rather than "(null)".
*
* @see palandprintf() for intuitive reference documentation
* @see __fmt() for intuitive reference documentation
* @see {,v}{,s{,n},{,{,x}as},f,d}printf
*/
int(printf)(const char* fmt, ...) {

View File

@ -8,6 +8,9 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int Printf(const char *, ...);
int Sprintf(char *, const char *, ...);
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

View File

@ -37,7 +37,8 @@ LIBC_STDIO_A_DIRECTDEPS = \
LIBC_STR \
LIBC_STUBS \
LIBC_SYSV \
LIBC_SYSV_CALLS
LIBC_SYSV_CALLS \
THIRD_PARTY_GDTOA
LIBC_STDIO_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_STDIO_A_DIRECTDEPS),$($(x))))

View File

@ -33,7 +33,7 @@ static noinstrument int vfprintfputchar(int c, struct state *st) {
int(vfprintf)(FILE *f, const char *fmt, va_list va) {
struct state st[1] = {{f, 0}};
if (palandprintf(vfprintfputchar, st, fmt, va) != -1) {
if (__fmt(vfprintfputchar, st, fmt, va) != -1) {
return st->n;
} else {
return -1;