cosmopolitan/libc/stdio
Gabriel Ravier 4754f200ee
Fix printf-family long double prec/rounding issues (#1283)
Currently, in cosmopolitan, there is no handling of the current rounding
mode for long double conversions, such that round-to-nearest gets always
used, regardless of the current rounding mode. %Le also improperly calls
gdtoa with a too small precision (which led to relatively similar bugs).

This patch fixes these issues, in particular by modifying the FPI object
passed to gdtoa such that it is modifiable (so that __fmt can adjust its
rounding field to correspond to FLT_ROUNDS (note that this is not needed
for dtoa, which checks FLT_ROUNDS directly)) and ors STRTOG_Neg into the
kind field in both of the __fmt_dfpbits and __fmt_ldfpbits functions, as
the gdtoa function also depends on it to be able to accurately round any
negative arguments. The change to kind also requires a few other changes
to make sure kind's upper bits (which include STRTOG_Neg) are masked off
when attempting to only examine the lower bits' value. Furthermore, this
patch also makes exactly one change in gdtoa, which appears to be needed
to fix rounding issues with FE_TOWARDZERO (this seems like a gdtoa bug).

The patch also adds a few tests for these issues, along with also taking
the opportunity to clean up some of the previous tests to do the asserts
in the right order (i.e. with the first argument as the expected result,
and the second one being used as the value that it is compared against).
2024-09-07 18:26:04 -07:00
..
__fpurge.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
__freadahead.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
__freadptr.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
__freadptrinc.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
__fseterr.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
alloc.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
alphasort.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
append.h Make cosmo.h work a little better 2024-02-21 16:40:09 -08:00
appendd.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
appendf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
appendr.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
appends.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
appendstrlist.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
appendw.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
appendz.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
asprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
atof.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
big5.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
BUILD.mk Implement proper time zone support 2024-05-04 23:06:37 -07:00
clearerr.c more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
clearerr_unlocked.c more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
codepages.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
confstr.c Put confstr() in unistd.h 2024-05-21 15:35:06 -07:00
ctermid.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
dirstream.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
dprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
dprintf.h Add dontthrow attribute to most libc functions 2024-01-09 01:26:03 -08:00
dumphexc.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
ecvt.c Fix ecvt/fcvt issues w.r.t. value==0 and ndigit==0 (#1282) 2024-09-07 18:08:11 -07:00
fbufsize.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fclose.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fdopen.c Fix stdio for character device regression 2024-05-25 05:58:09 -07:00
feof.c more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
feof_unlocked.c more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
ferror.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ferror_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fflush.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fflush.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
fflush_unlocked.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
fflushimpl.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fgetc.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fgetc_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fgetln.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fgetpos.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fgets.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fgets_unlocked.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
fgetwc.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fgetwc_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fgetws.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fgetws_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fileno.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fileno_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
flbf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fleaks.c Fix pthread_kill_test flake on qemu 2024-08-16 21:18:26 -07:00
flockfile.c Make some improvements of little consequence 2024-07-27 08:20:18 -07:00
flushlbf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fmemopen.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fmt.c Fix printf-family long double prec/rounding issues (#1283) 2024-09-07 18:26:04 -07:00
fopen.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fopenflags.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fpending.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fprintf_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fpurge.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fputc.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fputc_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fputs.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fputs_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
fputwc.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fputwc_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fputws.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fputws_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fread.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
fread_unlocked.c Make fread() more consistent with glibc 2024-08-17 02:57:22 -07:00
freadable.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
freading.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
freestrlist.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
freopen.c Fix some static analysis issues 2024-07-27 09:16:54 -07:00
fscanf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fseek.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
fseek_unlocked.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
fsetlocking.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fsetpos.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ftell.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
ftrylockfile.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ftw.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ftw.h Add dontthrow attribute to most libc functions 2024-01-09 01:26:03 -08:00
funlockfile.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fwritable.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fwrite.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
fwrite_unlocked.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
fwriting.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
g_rando.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
gb18030.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
gcvt.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
get_current_dir_name.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
getchar.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
getchar_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
getcwd.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
getdelim.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
getdelim_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
getentropy.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
getline.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
gets.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
getwchar.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
getwchar_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
hex.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
hkscs.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
iconv.h Reduce header complexity 2023-11-28 14:39:42 -08:00
internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
jis0208.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
joinstrlist.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
kappendf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ksc.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
kvappendf.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
lcg.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
legacychars.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
lemur64.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
mt19937.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
nftw.c Fix some static analysis issues 2024-07-27 09:16:54 -07:00
pclose.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
popen.c Fix some static analysis issues 2024-07-27 09:16:54 -07:00
printargs.c Avoid linker conflicts on DescribeFoo symbols 2024-08-24 18:10:22 -07:00
printf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
putchar.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
putchar_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
puts.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
puts_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
putwc_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
putwchar.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
putwchar_unlocked.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
rand.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
rand.h Add dontthrow attribute to most libc functions 2024-01-09 01:26:03 -08:00
random.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
rdseed.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
readpassphrase.c Fix ctype.h and wctype.h 2024-07-21 15:54:17 -07:00
readpassphrase.h Import libbsd readpassphrase (#1182) 2024-05-20 03:37:30 -04:00
real1.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
real2.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
real3.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
revjis.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
rewind.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
rngset.c Delete ASAN 2024-06-22 05:45:49 -07:00
scandir.c Fix some static analysis issues 2024-07-27 09:16:54 -07:00
scanf.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
setbuf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
setbuffer.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
setlinebuf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
setvbuf.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
snprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
sortstrlist.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
sprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
srand.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
sscanf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
stdbuf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
stderr.c Fix MODE=tinylinux build 2024-07-06 01:51:08 -07:00
stdin.c Fix MODE=tinylinux build 2024-07-06 01:51:08 -07:00
stdio.h Fix some static analysis issues 2024-07-27 09:16:54 -07:00
stdio_ext.h Add dontthrow attribute to most libc functions 2024-01-09 01:26:03 -08:00
stdout.c Fix MODE=tinylinux build 2024-07-06 01:51:08 -07:00
strfry.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
strlist.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
strtold.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
swprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
syscall.c Introduce getcpu() system call from glibc 2024-02-21 18:17:20 -08:00
syscall.h Introduce getcpu() system call from glibc 2024-02-21 18:17:20 -08:00
sysparam.h Rerun clang-format on the repo (#1217) 2024-06-15 16:34:48 -04:00
tmpfile.c Bring back gc() function 2024-01-08 10:26:28 -08:00
tmpnam.c Make improvements 2024-02-12 10:23:00 -08:00
tmpnam_r.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ungetc.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ungetc_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
ungetwc.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ungetwc_unlocked.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
vappendf.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
vasprintf.c Fix some static analysis issues 2024-07-27 09:16:54 -07:00
vcscanf.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
vdprintf.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
versionsort.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
vfprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
vfprintf_unlocked.c Support printf %n directive 2024-07-28 22:27:06 -07:00
vfscanf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
vigna.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
vprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
vscanf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
vsnprintf.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
vsprintf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
vsscanf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
wcstod.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
wcstof.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
wcstold.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00