1//===-- Common constants for math functions ---------------------*- 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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H
10#define LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H
11
12#include "src/__support/FPUtil/triple_double.h"
13#include "src/__support/number_pair.h"
14
15namespace LIBC_NAMESPACE {
16
17// Lookup table for (1/f) where f = 1 + n*2^(-7), n = 0..127.
18extern const double ONE_OVER_F[128];
19
20// Lookup table for log(f) = log(1 + n*2^(-7)) where n = 0..127.
21extern const double LOG_F[128];
22
23// Lookup table for range reduction constants r for logarithms.
24extern const float R[128];
25
26// Lookup table for range reduction constants r for logarithms.
27extern const double RD[128];
28
29// Lookup table for compensated constants for exact range reduction when FMA
30// instructions are not available.
31extern const double CD[128];
32
33// Lookup table for -log(r)
34extern const double LOG_R[128];
35extern const NumberPair<double> LOG_R_DD[128];
36
37// Lookup table for -log2(r)
38extern const double LOG2_R[128];
39
40// Minimax polynomial for (log(1 + x) - x)/x^2, generated by sollya with:
41// > P = fpminimax((log(1 + x) - x)/x^2, 5, [|D...|], [-2^-8, 2^-7]);
42constexpr double LOG_COEFFS[6] = {-0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2,
43 -0x1.0000000094567p-2, 0x1.99999dcc9823cp-3,
44 -0x1.55550ac2e537ap-3, 0x1.21a02c4e624d7p-3};
45
46// Logarithm Range Reduction - Step 2, 3, and 4.
47extern const int S2[193];
48extern const int S3[161];
49extern const int S4[130];
50
51extern const double R2[193];
52
53// log(2) generated by Sollya with:
54// > a = 2^-43 * nearestint(2^43*log(2));
55// LSB = 2^-43 is chosen so that e_x * LOG_2_HI is exact for -1075 < e_x < 1024.
56constexpr double LOG_2_HI = 0x1.62e42fefa38p-1; // LSB = 2^-43
57// > b = round(log10(2) - a, D, RN);
58constexpr double LOG_2_LO = 0x1.ef35793c7673p-45; // LSB = 2^-97
59
60// Lookup table for exp(m) with m = -104, ..., 89.
61// -104 = floor(log(single precision's min denormal))
62// 89 = ceil(log(single precision's max normal))
63// Table is generated with Sollya as follow:
64// > display = hexadecimal;
65// > for i from -104 to 89 do { D(exp(i)); };
66extern const double EXP_M1[195];
67
68// Lookup table for exp(m * 2^(-7)) with m = 0, ..., 127.
69// Table is generated with Sollya as follow:
70// > display = hexadecimal;
71// > for i from 0 to 127 do { D(exp(i / 128)); };
72extern const double EXP_M2[128];
73
74// Lookup table for 2^(k * 2^-6) with k = 0..63.
75extern const fputil::TripleDouble EXP2_MID1[64];
76
77// Lookup table for 2^(k * 2^-12) with k = 0..63.
78extern const fputil::TripleDouble EXP2_MID2[64];
79
80} // namespace LIBC_NAMESPACE
81
82#endif // LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H
83

source code of libc/src/math/generic/common_constants.h