diff options
Diffstat (limited to 'libc/test/src/math/sqrtbf16_test.cpp')
| -rw-r--r-- | libc/test/src/math/sqrtbf16_test.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libc/test/src/math/sqrtbf16_test.cpp b/libc/test/src/math/sqrtbf16_test.cpp new file mode 100644 index 000000000000..186ddd548713 --- /dev/null +++ b/libc/test/src/math/sqrtbf16_test.cpp @@ -0,0 +1,29 @@ +//===-- Exhaustive test for sqrtbf16 --------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/sqrtbf16.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +using LlvmLibcSqrtf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>; + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; + +// range: [0, inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7f80U; + +TEST_F(LlvmLibcSqrtf16Test, PositiveRange) { + for (uint16_t v = POS_START; v <= POS_STOP; ++v) { + bfloat16 x = FPBits(v).get_val(); + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sqrt, x, + LIBC_NAMESPACE::sqrtbf16(x), 0.5); + } +} |
