summaryrefslogtreecommitdiff
path: root/libc/test/src/stdio/sprintf_test.cpp
diff options
context:
space:
mode:
authorMichael Jones <michaelrj@google.com>2023-02-28 15:10:08 -0800
committerMichael Jones <michaelrj@google.com>2023-03-01 10:57:26 -0800
commitb39f1e5c13897b69c314febd014895a5ed23696e (patch)
tree6e7f71b5a9ece2d6131305509efdde22b97a621d /libc/test/src/stdio/sprintf_test.cpp
parent21fc42b2d594986a4ae28475b10c75bfe10d3bd2 (diff)
[libc] Fix printf %f rounding condition
When running the tbin2dec tests I found a rounding error in my code. Upon inspection I realized it was due to a lack of parenthesis when calculating the number of trailing digits. This patch fixes that mistake and adds unit tests to catch regressions in future. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D145011
Diffstat (limited to 'libc/test/src/stdio/sprintf_test.cpp')
-rw-r--r--libc/test/src/stdio/sprintf_test.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/libc/test/src/stdio/sprintf_test.cpp b/libc/test/src/stdio/sprintf_test.cpp
index 84a0faabb20a..a6a83154970a 100644
--- a/libc/test/src/stdio/sprintf_test.cpp
+++ b/libc/test/src/stdio/sprintf_test.cpp
@@ -1140,6 +1140,13 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
written = __llvm_libc::sprintf(buff, "%.5f", 1.008e3);
ASSERT_STREQ_LEN(written, buff, "1008.00000");
+ // Found with the help of Fred Tydeman's tbin2dec test.
+ written = __llvm_libc::sprintf(buff, "%.1f", 0x1.1000000000006p+3);
+ ASSERT_STREQ_LEN(written, buff, "8.5");
+
+ written = __llvm_libc::sprintf(buff, "%.0f", 0x1.1000000000006p+3);
+ ASSERT_STREQ_LEN(written, buff, "9");
+
// Subnormal Precision Tests
written = __llvm_libc::sprintf(buff, "%.310f", 0x1.0p-1022);