42 lines · cpp
1//===-- Full range tests for BFloat16 log(x) function ---------------------===//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/FPUtil/bfloat16.h"10#include "src/math/log_bf16.h"11#include "test/UnitTest/FPMatcher.h"12#include "test/UnitTest/Test.h"13#include "utils/MPFRWrapper/MPFRUtils.h"14 15using LlvmLibcLogBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;16 17namespace mpfr = LIBC_NAMESPACE::testing::mpfr;18 19// range: [0, inf]20static constexpr uint16_t POS_START = 0x0000U;21static constexpr uint16_t POS_STOP = 0x7f80U;22 23// range: [-0, -inf]24static constexpr uint16_t NEG_START = 0x8000U;25static constexpr uint16_t NEG_STOP = 0xff80U;26 27TEST_F(LlvmLibcLogBf16Test, PositiveRange) {28 for (uint16_t v = POS_START; v <= POS_STOP; ++v) {29 bfloat16 x = FPBits(v).get_val();30 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x,31 LIBC_NAMESPACE::log_bf16(x), 0.5);32 }33}34 35TEST_F(LlvmLibcLogBf16Test, NegativeRange) {36 for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {37 bfloat16 x = FPBits(v).get_val();38 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x,39 LIBC_NAMESPACE::log_bf16(x), 0.5);40 }41}42