>From 21bfd0ea5f8e9534203f075b54077499fa693d95 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 21 May 2026 13:30:01 -0400 Subject: [PATCH] functional: add tests for strto[l]d rounding just past end of mantissa --- src/functional/strtod.c | 3 +++ src/functional/strtold.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/functional/strtod.c b/src/functional/strtod.c index 2e4b3fd..48db86b 100644 --- a/src/functional/strtod.c +++ b/src/functional/strtod.c @@ -38,6 +38,9 @@ static struct { "02630657488671505820681908902000708383676273854845817711531764475730" "27006985557136695962284291481986083493647529271907416844436551070434" "2711559699508093042880177904174497792", INFINITY}, + // rounding at end of mantissa + {"0x1.111111111111281", 0x1.1111111111113p0}, + {"0x1.11111111111111", 0x1.1111111111111p0}, // some random numbers {".5961860348131807091861002266453941950428e00", 0.59618603481318067}, // 0x1.313f4bc3b584cp-1 {"1.815013169218038729887460898733526957442e-1", 0.18150131692180388}, // 0x1.73b6f662e1712p-3 diff --git a/src/functional/strtold.c b/src/functional/strtold.c index 6ea1672..7c6e59c 100644 --- a/src/functional/strtold.c +++ b/src/functional/strtold.c @@ -59,6 +59,9 @@ static struct { {"0.2346324356502437045212230713960457676531e6", 234632.43565024371}, // 0x1.ca4437c3631eap+17 {"0.9709481716420048341897258980454298205278e8", 97094817.164200485}, // 0x1.7263284a8242cp+26 {"0.4996908522051874110779982354932499499602e9", 499690852.20518744}, // 0x1.dc8ad6434872ap+28 + // rounding at end of mantissa + {"0x1.111111111111281", 0x1.1111111111113p0}, + {"0x1.11111111111111", 0x1.1111111111111p0}, #elif LDBL_MANT_DIG == 64 // 2^-16445 * 0.5 - eps {".1822599765941237301264202966809709908199525407846781671860490243514185844316698e-4950", 0}, @@ -76,6 +79,13 @@ static struct { {"118973149535723176505351158982948.86679662540046955672e4900", 0x1.fffffffffffffffep16383L}, // 2^16384 - 2^16319 + eps {"118973149535723176505351158982948.86679662540046955673e4900", INFINITY}, + // rounding at end of mantissa + {"0x8.11111111111111281", 0x8.111111111111113p0}, + {"0x8.1111111111111111", 0x8.111111111111111p0}, +#elif LDBL_MANT_DIG == 113 + // rounding at end of mantissa + {"0x1.111111111111111111111111111281", 0x1.1111111111111111111111111113p0}, + {"0x1.11111111111111111111111111111", 0x1.1111111111111111111111111111p0}, #endif }; -- 2.21.0