brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · b3ee5bb Raw
77 lines · c
1//===-- Implementation header for atanhf ------------------------*- C++ -*-===//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#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ATANHF_H10#define LLVM_LIBC_SRC___SUPPORT_MATH_ATANHF_H11 12#include "acoshf_utils.h"13#include "src/__support/FPUtil/FEnvImpl.h"14#include "src/__support/FPUtil/FPBits.h"15#include "src/__support/macros/config.h"16#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY17 18namespace LIBC_NAMESPACE_DECL {19 20namespace math {21 22LIBC_INLINE static constexpr float atanhf(float x) {23  using namespace acoshf_internal;24  using FPBits = typename fputil::FPBits<float>;25 26  FPBits xbits(x);27  Sign sign = xbits.sign();28  uint32_t x_abs = xbits.abs().uintval();29 30  // |x| >= 1.031  if (LIBC_UNLIKELY(x_abs >= 0x3F80'0000U)) {32    if (xbits.is_nan()) {33      if (xbits.is_signaling_nan()) {34        fputil::raise_except_if_required(FE_INVALID);35        return FPBits::quiet_nan().get_val();36      }37      return x;38    }39    // |x| == 1.040    if (x_abs == 0x3F80'0000U) {41      fputil::set_errno_if_required(ERANGE);42      fputil::raise_except_if_required(FE_DIVBYZERO);43      return FPBits::inf(sign).get_val();44    } else {45      fputil::set_errno_if_required(EDOM);46      fputil::raise_except_if_required(FE_INVALID);47      return FPBits::quiet_nan().get_val();48    }49  }50 51  // |x| < ~0.1052  if (LIBC_UNLIKELY(x_abs <= 0x3dcc'0000U)) {53    // |x| <= 2^-2654    if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) {55      return static_cast<float>(LIBC_UNLIKELY(x_abs == 0)56                                    ? x57                                    : (x + 0x1.5555555555555p-2 * x * x * x));58    }59 60    double xdbl = x;61    double x2 = xdbl * xdbl;62    // Pure Taylor series.63    double pe = fputil::polyeval(x2, 0.0, 0x1.5555555555555p-2,64                                 0x1.999999999999ap-3, 0x1.2492492492492p-3,65                                 0x1.c71c71c71c71cp-4, 0x1.745d1745d1746p-4);66    return static_cast<float>(fputil::multiply_add(xdbl, pe, xdbl));67  }68  double xdbl = x;69  return static_cast<float>(0.5 * log_eval((xdbl + 1.0) / (xdbl - 1.0)));70}71 72} // namespace math73 74} // namespace LIBC_NAMESPACE_DECL75 76#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ATANHF_H77