diff --git a/test/source/scwx/util/float.test.cpp b/test/source/scwx/util/float.test.cpp index f91fe4bf..aa4bfe7e 100644 --- a/test/source/scwx/util/float.test.cpp +++ b/test/source/scwx/util/float.test.cpp @@ -7,6 +7,11 @@ namespace scwx namespace util { +class Float16Test : + public testing ::TestWithParam> +{ +}; + TEST(FloatTest, Decode32Positive1) { uint16_t msw = 0x3f80; @@ -37,14 +42,26 @@ TEST(FloatTest, Decode32Positive12345678) EXPECT_FLOAT_EQ(x, 12345678.0f); } -TEST(FloatTest, Decode16h0x5bb4) +TEST_P(Float16Test, DecodeFloat16) { - uint16_t hex = 0x5bb4; + auto param = GetParam(); + + std::uint16_t hex = param.first; float x = DecodeFloat16(hex); - EXPECT_FLOAT_EQ(x, 123.25f); + EXPECT_FLOAT_EQ(x, param.second); } +INSTANTIATE_TEST_SUITE_P( + FloatTest, + Float16Test, + testing::Values(std::pair {0x4400, 2.0f}, + std::pair {0x59ab, 90.6875f}, + std::pair {0x593e, 83.875f}, + std::pair {0x54dc, 38.875f}, + std::pair {0xc82a, -4.1640625f}, + std::pair {0x5bb4, 123.25f})); + } // namespace util } // namespace scwx diff --git a/wxdata/source/scwx/util/float.cpp b/wxdata/source/scwx/util/float.cpp index cee8ae66..3aea2dd6 100644 --- a/wxdata/source/scwx/util/float.cpp +++ b/wxdata/source/scwx/util/float.cpp @@ -19,7 +19,7 @@ float DecodeFloat16(std::uint16_t hex) static constexpr std::uint16_t S_MASK = 0x8000; static constexpr std::uint16_t S_LSB = 0; static constexpr std::uint16_t S_SHIFT = 15 - S_LSB; - static constexpr std::uint16_t E_MASK = 0x7a00; + static constexpr std::uint16_t E_MASK = 0x7c00; static constexpr std::uint16_t E_LSB = 5; static constexpr std::uint16_t E_SHIFT = 15 - E_LSB; static constexpr std::uint16_t F_MASK = 0x03ff;