Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libc/src/__support/float_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ FloatToString<long double>::get_negative_block(int block_index) {
const int32_t SHIFT_CONST = TABLE_SHIFT_CONST;

// if the requested block is zero
if (block_index <= MIN_BLOCK_2[idx]) {
if (block_index < MIN_BLOCK_2[idx]) {
return 0;
}
const uint32_t p = POW10_OFFSET_2[idx] + block_index - MIN_BLOCK_2[idx];
Expand Down
19 changes: 19 additions & 0 deletions libc/test/src/stdio/sprintf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,9 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%g", 9999999000000.00);
ASSERT_STREQ_LEN(written, buff, "1e+13");

written = LIBC_NAMESPACE::sprintf(buff, "%g", 0xa.aaaaaaaaaaaaaabp-7);
ASSERT_STREQ_LEN(written, buff, "0.0833333");

// Simple Subnormal Tests.

written = LIBC_NAMESPACE::sprintf(buff, "%g", 0x1.0p-1027);
Expand All @@ -2457,9 +2460,16 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {

// Length Modifier Tests.

#if defined(SPECIAL_X86_LONG_DOUBLE)

written = LIBC_NAMESPACE::sprintf(buff, "%Lg", 0xf.fffffffffffffffp+16380L);
ASSERT_STREQ_LEN(written, buff, "1.18973e+4932");

written = LIBC_NAMESPACE::sprintf(buff, "%Lg", 0xa.aaaaaaaaaaaaaabp-7L);
ASSERT_STREQ_LEN(written, buff, "0.0833333");

#endif // SPECIAL_X86_LONG_DOUBLE

// TODO: Uncomment the below tests after long double support is added
/*
written = LIBC_NAMESPACE::sprintf(buff, "%Lf", 1e100L);
Expand Down Expand Up @@ -2757,6 +2767,15 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.10g", 0x1.0p-1074);
ASSERT_STREQ_LEN(written, buff, "4.940656458e-324");

#if defined(SPECIAL_X86_LONG_DOUBLE)

written = LIBC_NAMESPACE::sprintf(buff, "%.60Lg", 0xa.aaaaaaaaaaaaaabp-7L);
ASSERT_STREQ_LEN(
written, buff,
"0.0833333333333333333355920878593448009041821933351457118988037");

#endif // SPECIAL_X86_LONG_DOUBLE

// Long double precision tests.
// These are currently commented out because they require long double support
// that isn't ready yet.
Expand Down