diff --git a/libc/src/math/generic/log2f.cpp b/libc/src/math/generic/log2f.cpp --- a/libc/src/math/generic/log2f.cpp +++ b/libc/src/math/generic/log2f.cpp @@ -105,11 +105,24 @@ int m = 0; // Hard to round value(s). - if (FPBits(x).uintval() == 0x3f81d0b5U) { + switch (FPBits(x).uintval()) { + case 0x3f81d0b5U: { int rounding_mode = fputil::get_round(); if (rounding_mode == FE_DOWNWARD || rounding_mode == FE_TOWARDZERO) { return 0x1.4cdc4cp-6f; } + break; + } + case 0x3f7e3274U: + if (fputil::get_round() == FE_TONEAREST) { + return -0x1.4e1d16p-7f; + } + break; + case 0x3f7d57f5U: + if (fputil::get_round() == FE_TOWARDZERO) { + return -0x1.ed1c32p-7f; + } + break; } // Exceptional inputs. diff --git a/libc/test/src/math/log2f_test.cpp b/libc/test/src/math/log2f_test.cpp --- a/libc/test/src/math/log2f_test.cpp +++ b/libc/test/src/math/log2f_test.cpp @@ -31,10 +31,10 @@ } TEST(LlvmLibcLog2fTest, TrickyInputs) { - constexpr int N = 9; - constexpr uint32_t INPUTS[N] = {0x3f7d57f5U, 0x3f7ed848U, 0x3f7fd6ccU, - 0x3f7fffffU, 0x3f80079bU, 0x3f81d0b5U, - 0x3f82e602U, 0x3f83c98dU, 0x3f8cba39U}; + constexpr int N = 10; + constexpr uint32_t INPUTS[N] = { + 0x3f7d57f5U, 0x3f7e3274U, 0x3f7ed848U, 0x3f7fd6ccU, 0x3f7fffffU, + 0x3f80079bU, 0x3f81d0b5U, 0x3f82e602U, 0x3f83c98dU, 0x3f8cba39U}; for (int i = 0; i < N; ++i) { float x = float(FPBits(INPUTS[i]));