brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · d277b12 Raw
47 lines · cpp
1//===-- Exhaustive test for log2f16 ---------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/macros/optimization.h"10#include "src/math/log2f16.h"11#include "test/UnitTest/FPMatcher.h"12#include "test/UnitTest/Test.h"13#include "utils/MPFRWrapper/MPFRUtils.h"14 15#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS16#define TOLERANCE 117#else18#define TOLERANCE 019#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS20using LlvmLibcLog2f16Test = LIBC_NAMESPACE::testing::FPTest<float16>;21 22namespace mpfr = LIBC_NAMESPACE::testing::mpfr;23 24// Range: [0, Inf];25static constexpr uint16_t POS_START = 0x0000U;26static constexpr uint16_t POS_STOP = 0x7c00U;27 28// Range: [-Inf, 0];29static constexpr uint16_t NEG_START = 0x8000U;30static constexpr uint16_t NEG_STOP = 0xfc00U;31 32TEST_F(LlvmLibcLog2f16Test, PositiveRange) {33  for (uint16_t v = POS_START; v <= POS_STOP; ++v) {34    float16 x = FPBits(v).get_val();35    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x,36                                   LIBC_NAMESPACE::log2f16(x), TOLERANCE + 0.5);37  }38}39 40TEST_F(LlvmLibcLog2f16Test, NegativeRange) {41  for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {42    float16 x = FPBits(v).get_val();43    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x,44                                   LIBC_NAMESPACE::log2f16(x), TOLERANCE + 0.5);45  }46}47