llvm-project/libc/utils/FPUtil/BitPatterns.h
Tue Ly 4e5f8b4d8d [libc] Add implementation of expm1f.
Use expm1f(x) = exp(x) - 1 for |x| > ln(2).
For |x| <= ln(2), divide it into 3 subintervals: [-ln2, -1/8], [-1/8, 1/8], [1/8, ln2]
and use a degree-6 polynomial approximation generated by Sollya's fpminmax for each interval.
Errors < 1.5 ULPs when we use fma to evaluate the polynomials.

Differential Revision: https://reviews.llvm.org/D101134
2021-06-10 14:58:34 -04:00

70 lines
2.2 KiB
C++

//===-- Bit patterns of common floating point numbers -----------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_UTILS_FPUTIL_BIT_PATTERNS_H
#define LLVM_LIBC_UTILS_FPUTIL_BIT_PATTERNS_H
#include "FloatProperties.h"
#include <float.h>
static_assert(
FLT_RADIX == 2,
"LLVM libc only supports radix 2 IEEE 754 floating point formats.");
namespace __llvm_libc {
namespace fputil {
template <typename T> struct BitPatterns {};
template <> struct BitPatterns<float> {
using BitsType = FloatProperties<float>::BitsType;
static constexpr BitsType inf = 0x7f800000U;
static constexpr BitsType negInf = 0xff800000U;
static constexpr BitsType zero = 0x0;
static constexpr BitsType negZero = 0x80000000U;
static constexpr BitsType one = 0x3f800000U;
static constexpr BitsType negOne = 0xbf800000U;
// Examples of quiet NAN.
static constexpr BitsType aQuietNaN = 0x7fc00000U;
static constexpr BitsType aNegativeQuietNaN = 0xffc00000U;
// Examples of signalling NAN.
static constexpr BitsType aSignallingNaN = 0x7f800001U;
static constexpr BitsType aNegativeSignallingNaN = 0xff800001U;
};
template <> struct BitPatterns<double> {
using BitsType = FloatProperties<double>::BitsType;
static constexpr BitsType inf = 0x7ff0000000000000ULL;
static constexpr BitsType negInf = 0xfff0000000000000ULL;
static constexpr BitsType zero = 0x0ULL;
static constexpr BitsType negZero = 0x8000000000000000ULL;
static constexpr BitsType one = 0x3FF0000000000000ULL;
// Examples of quiet NAN.
static constexpr BitsType aQuietNaN = 0x7ff8000000000000ULL;
static constexpr BitsType aNegativeQuietNaN = 0xfff8000000000000ULL;
// Examples of signalling NAN.
static constexpr BitsType aSignallingNaN = 0x7ff0000000000001ULL;
static constexpr BitsType aNegativeSignallingNaN = 0xfff0000000000001ULL;
};
} // namespace fputil
} // namespace __llvm_libc
#endif // LLVM_LIBC_UTILS_FPUTIL_BIT_PATTERNS_H