commit 1647c0a2bfde02822f90d210221d28452d82c16f
parent 74bb8047e8db6ddfb0da71f658dad2a0326c4a1c
Author: Sebastian <sebastian@sebsite.pw>
Date: Thu, 7 Nov 2024 19:21:18 -0500
strconv: don't fall back to multiprecision for scientific notation
6.022e23 previously didn't format correctly when SHOW_POINT was used.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/strconv/+test/ftos_test.ha b/strconv/+test/ftos_test.ha
@@ -160,6 +160,8 @@ use memio;
(1000.0, ffmt::G, 0, fflags::SHOW_POINT, "1.0e3"),
(0.0123, ffmt::G, 2, fflags::SHOW_POINT, "0.012"),
(0.0123, ffmt::G, 5, fflags::SHOW_POINT, "0.0123"),
+ // regression test
+ (6.022e23, ffmt::G, void, fflags::SHOW_POINT, "6.022e23"),
];
const stream = memio::dynamic();
defer io::close(&stream)!;
diff --git a/strconv/ftos.ha b/strconv/ftos.ha
@@ -362,7 +362,8 @@ export fn fftosf(
init_dec_mant_exp(&dec, mdec, edec);
// If SHOW_POINT and we have too few digits, then we need to
// fall back to multiprecision.
- ok = !ffpoint(flag) || dec.dp < dec.nd: i32;
+ ok = !ffpoint(flag) || dec.dp < dec.nd: i32
+ || (f != ffmt::F && dec.dp - dec.nd: i32 > 2);
};
if (!ok) {