|
| 1 | +//===-- Unittests for cbrtf16 ---------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "hdr/math_macros.h" |
| 10 | +#include "src/__support/FPUtil/FPBits.h" |
| 11 | +#include "src/math/cbrtf16.h" |
| 12 | +#include "test/UnitTest/FPMatcher.h" |
| 13 | +#include "test/UnitTest/Test.h" |
| 14 | +#include "utils/MPFRWrapper/MPFRUtils.h" |
| 15 | + |
| 16 | +using LlvmLibcCbrtf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; |
| 17 | + |
| 18 | +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; |
| 19 | + |
| 20 | +// Range: [0, Inf]; |
| 21 | +static constexpr uint16_t POS_START = 0x0000U; |
| 22 | +static constexpr uint16_t POS_STOP = 0x7c00U; |
| 23 | + |
| 24 | +// Range: [-Inf, 0] |
| 25 | +static constexpr uint16_t NEG_START = 0x8000U; |
| 26 | +static constexpr uint16_t NEG_STOP = 0xfc00U; |
| 27 | + |
| 28 | +TEST_F(LlvmLibcCbrtf16Test, PositiveRange) { |
| 29 | + for (uint16_t v = POS_START; v <= POS_STOP; ++v) { |
| 30 | + float16 x = FPBits(v).get_val(); |
| 31 | + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cbrt, x, |
| 32 | + LIBC_NAMESPACE::cbrtf16(x), 0.5); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +TEST_F(LlvmLibcCbrtf16Test, NegativeRange) { |
| 37 | + for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { |
| 38 | + float16 x = FPBits(v).get_val(); |
| 39 | + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cbrt, x, |
| 40 | + LIBC_NAMESPACE::cbrtf16(x), 0.5); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +TEST_F(LlvmLibcCbrtf16Test, SpecialValues) { |
| 45 | + constexpr uint16_t INPUTS[] = { |
| 46 | + 0x4a00, 0x4500, 0x4e00, 0x0c00, 0x4940, |
| 47 | + }; |
| 48 | + for (uint16_t v : INPUTS) { |
| 49 | + float16 x = FPBits(v).get_val(); |
| 50 | + mpfr::ForceRoundingMode r(mpfr::RoundingMode::Upward); |
| 51 | + EXPECT_MPFR_MATCH(mpfr::Operation::Cbrt, x, LIBC_NAMESPACE::cbrtf16(x), 0.5, |
| 52 | + mpfr::RoundingMode::Upward); |
| 53 | + } |
| 54 | + |
| 55 | + ASSERT_EQ(1, 1); |
| 56 | +} |
0 commit comments