[llvm] [APFloat] Add `APFloat::getConstant` for C++20 <numbers> constants (PR #227916)
Eric Ross via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 17:46:18 PDT 2026
https://github.com/ZERICO2005 created https://github.com/llvm/llvm-project/pull/227916
Implements https://github.com/llvm/llvm-project/issues/227811
I've added just the constants from C++20 `<numbers>` (`sqrtpi` and `inv_sqrt2` are not in C++20 `<numbers>`).
`PPCDoubleDouble` constants are limited to 106 bits of precision because the string to `PPCDoubleDouble` routines internally use `PPCDoubleDoubleLegacy` (which only have 106 bits of precision).
>From 43a9f786b20ef8aac57f4e6c66b579ecb804e69c Mon Sep 17 00:00:00 2001
From: zerico <zerico2005 at gmail.com>
Date: Wed, 30 Sep 2026 18:39:20 -0600
Subject: [PATCH] [APFloat] Add APFloat::getConstant for C++20 <numbers>
constants
---
llvm/include/llvm/ADT/APFloat.h | 29 ++
llvm/lib/Support/APFloat.cpp | 47 ++
.../lib/Transforms/Utils/SimplifyLibCalls.cpp | 7 +-
llvm/unittests/ADT/APFloatTest.cpp | 125 +++++
llvm/unittests/ADT/APFloatTestConstants.h | 447 ++++++++++++++++++
5 files changed, 653 insertions(+), 2 deletions(-)
create mode 100644 llvm/unittests/ADT/APFloatTestConstants.h
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index b51b6256ad2c6..454e3d7b0cbde 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -1271,6 +1271,35 @@ class APFloat : public APFloatBase {
/// \param Semantics - type float semantics
LLVM_ABI static APFloat getAllOnesValue(const fltSemantics &Semantics);
+ /// Constants from C++20 <numbers>
+ enum class MathConstant {
+ e,
+ log2e,
+ log10e,
+ pi,
+ inv_pi,
+ inv_sqrtpi,
+ ln2,
+ ln10,
+ sqrt2,
+ sqrt3,
+ inv_sqrt3,
+ egamma,
+ phi,
+ };
+
+ /// Returns the mathematical constant \p C rounded to the given semantics.
+ ///
+ /// TODO: ppc_fp128 constants are currently limited to 106 bits of precision.
+ ///
+ /// \param C - the constant to materialize
+ /// \param Sem - type float semantics
+ /// \param Negative - True iff the number should be negative
+ /// \param RM - the rounding mode used to round the exact value to \p Sem
+ LLVM_ABI static APFloat getConstant(MathConstant C, const fltSemantics &Sem,
+ bool Negative = false,
+ roundingMode RM = rmNearestTiesToEven);
+
/// Returns true if the given semantics has actual significand.
///
/// \param Sem - type float semantics
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 3d1932454761f..d8f08564a1ff7 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -6061,6 +6061,53 @@ APFloat APFloat::getAllOnesValue(const fltSemantics &Semantics) {
return APFloat(Semantics, APInt::getAllOnes(Semantics.sizeInBits));
}
+// The same literals as <numbers>, which are of sufficient precision for f128
+// and ppcf128. These literals will need to be updated if we add support for
+// f256 in the future.
+static constexpr StringLiteral MathConstantStrings[] = {
+ "-2.718281828459045235360287471352662498", // e
+ "-1.442695040888963407359924681001892137", // log2e
+ "-0.434294481903251827651128918916605082", // log10e
+ "-3.141592653589793238462643383279502884", // pi
+ "-0.318309886183790671537767526745028724", // inv_pi
+ "-0.564189583547756286948079451560772586", // inv_sqrtpi
+ "-0.693147180559945309417232121458176568", // ln2
+ "-2.302585092994045684017991454684364208", // ln10
+ "-1.414213562373095048801688724209698079", // sqrt2
+ "-1.732050807568877293527446341505872367", // sqrt3
+ "-0.577350269189625764509148780501957456", // inv_sqrt3
+ "-0.577215664901532860606512090082402431", // egamma
+ "-1.618033988749894848204586834365638118", // phi
+};
+
+static_assert(std::size(MathConstantStrings) ==
+ static_cast<size_t>(APFloat::MathConstant::phi) + 1,
+ "MathConstantStrings is out of sync with APFloat::MathConstant");
+
+APFloat APFloat::getConstant(MathConstant C, const fltSemantics &Sem,
+ bool Negative, roundingMode RM) {
+ assert(static_cast<size_t>(C) < std::size(MathConstantStrings) &&
+ "Unknown mathematical constant");
+
+ // Round the exact value, rather than the negation of the rounded value, so
+ // that directed rounding modes stay faithful to the sign of the result.
+ StringRef Str = MathConstantStrings[static_cast<size_t>(C)];
+ if (!Negative)
+ Str = Str.drop_front();
+
+ // IEEEQuad is the highest precision type we currently support.
+ constexpr unsigned int PrecisionOfIEEEQuad = 113;
+ // We special case semPPCDoubleDouble since it has a precision of 0.
+ assert((&Sem == &semPPCDoubleDouble ||
+ (Sem.precision > 0 && Sem.precision <= PrecisionOfIEEEQuad)) &&
+ "Literals are too short for this semantics (or semantics is invalid)");
+ APFloat Val(Sem);
+ auto StatusOrErr = Val.convertFromString(Str, RM);
+ assert(StatusOrErr && "Invalid floating point representation");
+ consumeError(StatusOrErr.takeError());
+ return Val;
+}
+
void APFloat::print(raw_ostream &OS) const {
SmallVector<char, 16> Buffer;
toString(Buffer);
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index f6235b5b98fcb..8e3e98b6033f4 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2829,8 +2829,11 @@ Value *LibCallSimplifier::optimizeLog(CallInst *Log, IRBuilderBase &B) {
ArgID == Intrinsic::exp || ArgID == Intrinsic::exp2) {
Constant *Eul;
if (ArgLb == ExpLb || ArgID == Intrinsic::exp)
- // FIXME: Add more precise value of e for long double.
- Eul = ConstantFP::get(Log->getType(), numbers::e);
+ Eul = ConstantFP::get(
+ Log->getType(),
+ APFloat::getConstant(
+ APFloat::MathConstant::e,
+ Log->getType()->getScalarType()->getFltSemantics()));
else if (ArgLb == Exp2Lb || ArgID == Intrinsic::exp2)
Eul = ConstantFP::get(Log->getType(), 2.0);
else
diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp
index 40a121232fd29..7f1e70f20d973 100644
--- a/llvm/unittests/ADT/APFloatTest.cpp
+++ b/llvm/unittests/ADT/APFloatTest.cpp
@@ -7,8 +7,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/APFloat.h"
+#include "APFloatTestConstants.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@@ -2582,6 +2584,129 @@ TEST(APFloatTest, ConvertLosesUnrepresentableSignAndZero) {
}
}
+// Parses a table entry, requiring that it be exactly representable in Sem. This
+// ensures that the value is not silently rounded to a different value.
+static void parseExactly(const fltSemantics &Sem,
+ const MathConstantRoundings &T, const char *Column,
+ const char *Str, APFloat &Out) {
+ Out = APFloat(Sem);
+ Expected<APFloat::opStatus> StatusOrErr =
+ Out.convertFromString(Str, APFloat::rmNearestTiesToEven);
+ ASSERT_TRUE(!!StatusOrErr)
+ << T.Name << " " << Column << ": cannot parse \"" << Str << "\"";
+ ASSERT_EQ(APFloat::opOK, *StatusOrErr)
+ << T.Name << " " << Column << ": \"" << Str
+ << "\" is not exactly representable in this format";
+}
+
+// Checks every rounding mode against ConstantsTable for both signs.
+// No constant is exactly representable in these formats, and none lies exactly
+// halfway between two representable values, so RNE is unambiguous.
+static void checkMathConstants(const fltSemantics &Sem,
+ ArrayRef<MathConstantRoundings> ConstantsTable,
+ bool IsPPCDoubleDouble = false) {
+ for (const MathConstantRoundings &T : ConstantsTable) {
+ APFloat PosDown(Sem);
+ APFloat PosRNE(Sem);
+ APFloat PosUp(Sem);
+ // The floating point literals should be exact.
+ ASSERT_NO_FATAL_FAILURE(parseExactly(Sem, T, "Down", T.Down, PosDown));
+ ASSERT_NO_FATAL_FAILURE(parseExactly(Sem, T, "RNE", T.RNE, PosRNE));
+ ASSERT_NO_FATAL_FAILURE(parseExactly(Sem, T, "Up", T.Up, PosUp));
+
+ APFloat NegRNE = PosRNE;
+ APFloat NegUp = PosUp;
+ APFloat NegDown = PosDown;
+ NegRNE.changeSign();
+ NegUp.changeSign();
+ NegDown.changeSign();
+
+ auto ToHex = [](const APFloat &V) {
+ SmallString<80> S;
+ V.bitcastToAPInt().toStringUnsigned(S, /*Radix=*/16);
+ return std::string(S);
+ };
+ auto Check = [&](const char *Mode, bool Negative, APFloat::roundingMode RM,
+ const APFloat &Expected) {
+ APFloat Got = APFloat::getConstant(T.Constant, Sem, Negative, RM);
+ EXPECT_TRUE(Got.bitwiseIsEqual(Expected))
+ << T.Name << (Negative ? " (negative) " : " ") << Mode << ": got 0x"
+ << ToHex(Got) << ", expected 0x" << ToHex(Expected);
+ };
+
+ Check("rmNearestTiesToEven", false, APFloat::rmNearestTiesToEven, PosRNE);
+ Check("rmNearestTiesToAway", false, APFloat::rmNearestTiesToAway, PosRNE);
+ Check("rmTowardPositive", false, APFloat::rmTowardPositive, PosUp);
+ Check("rmTowardNegative", false, APFloat::rmTowardNegative, PosDown);
+ Check("rmTowardZero", false, APFloat::rmTowardZero, PosDown);
+
+ // The exact value is negated before rounding rather than after, so the
+ // directed modes swap: rounding -x toward +inf selects -Down, not -Up.
+ Check("rmNearestTiesToEven", true, APFloat::rmNearestTiesToEven, NegRNE);
+ Check("rmNearestTiesToAway", true, APFloat::rmNearestTiesToAway, NegRNE);
+ Check("rmTowardPositive", true, APFloat::rmTowardPositive, NegDown);
+ Check("rmTowardNegative", true, APFloat::rmTowardNegative, NegUp);
+ Check("rmTowardZero", true, APFloat::rmTowardZero, NegDown);
+
+ // Down and Up bracket the exact value, and RNE should be equal to either
+ // Down or Up.
+ EXPECT_TRUE(PosDown.compare(PosUp) == APFloat::cmpLessThan) << T.Name;
+ EXPECT_TRUE(PosDown.bitwiseIsEqual(PosRNE) || PosUp.bitwiseIsEqual(PosRNE))
+ << T.Name;
+
+ // Down and Up should be adjacent, no value should be inbetween them.
+ // TODO: String to PPCDoubleDouble does not have enough precision to
+ // guarantee this property currently.
+ if (!IsPPCDoubleDouble) {
+ APFloat NextUp = PosDown;
+ EXPECT_EQ(APFloat::opOK, NextUp.next(/*nextDown=*/false)) << T.Name;
+ EXPECT_TRUE(NextUp.bitwiseIsEqual(PosUp)) << T.Name;
+ }
+ }
+}
+
+TEST(APFloatTest, getConstant) {
+ checkMathConstants(APFloat::BFloat(), ConstantsBFloat);
+ checkMathConstants(APFloat::IEEEhalf(), ConstantsIEEEhalf);
+ checkMathConstants(APFloat::IEEEsingle(), ConstantsIEEEsingle);
+ checkMathConstants(APFloat::IEEEdouble(), ConstantsIEEEdouble);
+ checkMathConstants(APFloat::x87DoubleExtended(), ConstantsX87DoubleExtended);
+ checkMathConstants(APFloat::IEEEquad(), ConstantsIEEEquad);
+
+ auto GetDoubleConstant = [](APFloat::MathConstant C) -> double {
+ return APFloat::getConstant(C, APFloat::IEEEdouble()).convertToDouble();
+ };
+
+ // Test agreement between APFloat::MathConstant and llvm::numbers
+ EXPECT_EQ(numbers::e, GetDoubleConstant(APFloat::MathConstant::e));
+ EXPECT_EQ(numbers::log2e, GetDoubleConstant(APFloat::MathConstant::log2e));
+ EXPECT_EQ(numbers::log10e, GetDoubleConstant(APFloat::MathConstant::log10e));
+ EXPECT_EQ(numbers::pi, GetDoubleConstant(APFloat::MathConstant::pi));
+ EXPECT_EQ(numbers::inv_pi, GetDoubleConstant(APFloat::MathConstant::inv_pi));
+ EXPECT_EQ(numbers::inv_sqrtpi,
+ GetDoubleConstant(APFloat::MathConstant::inv_sqrtpi));
+ EXPECT_EQ(numbers::ln2, GetDoubleConstant(APFloat::MathConstant::ln2));
+ EXPECT_EQ(numbers::ln10, GetDoubleConstant(APFloat::MathConstant::ln10));
+ EXPECT_EQ(numbers::sqrt2, GetDoubleConstant(APFloat::MathConstant::sqrt2));
+ EXPECT_EQ(numbers::sqrt3, GetDoubleConstant(APFloat::MathConstant::sqrt3));
+ EXPECT_EQ(numbers::inv_sqrt3,
+ GetDoubleConstant(APFloat::MathConstant::inv_sqrt3));
+ EXPECT_EQ(numbers::egamma, GetDoubleConstant(APFloat::MathConstant::egamma));
+ EXPECT_EQ(numbers::phi, GetDoubleConstant(APFloat::MathConstant::phi));
+
+ // TODO: Currently string to PPCDoubleDouble goes through
+ // PPCDoubleDoubleLegacy, so APFloat::getConstant can only produce constants
+ // for PPCDoubleDouble with up to 106 bits of precision instead of the up to
+ // 2098 bits (1023 - -1074 + 1) of precision that PPCDoubleDouble is capable
+ // of representing. These tests will have to be updated if the string to
+ // PPCDoubleDouble is properly implemented.
+ checkMathConstants(APFloat::PPCDoubleDouble(), ConstantsPPCDoubleDoubleLegacy,
+ /*IsPPCDoubleDouble=*/true);
+
+ // Edge case testing.
+ checkMathConstants(APFloat::Float6E3M2FN(), ConstantsFloat6E3M2FN);
+}
+
TEST(APFloatTest, getLargest) {
EXPECT_EQ(3.402823466e+38f, APFloat::getLargest(APFloat::IEEEsingle()).convertToFloat());
EXPECT_EQ(1.7976931348623158e+308, APFloat::getLargest(APFloat::IEEEdouble()).convertToDouble());
diff --git a/llvm/unittests/ADT/APFloatTestConstants.h b/llvm/unittests/ADT/APFloatTestConstants.h
new file mode 100644
index 0000000000000..426dcb2303970
--- /dev/null
+++ b/llvm/unittests/ADT/APFloatTestConstants.h
@@ -0,0 +1,447 @@
+//===- llvm/unittest/ADT/APFloatTestConstants.h - Constants for tests -----===//
+//
+// 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_UNITTESTS_ADT_APFLOATTESTCONSTANTS_H
+#define LLVM_UNITTESTS_ADT_APFLOATTESTCONSTANTS_H
+
+#include "llvm/ADT/APFloat.h"
+
+namespace llvm {
+namespace {
+
+// Expected results for APFloat::getConstant, one table per format: the exact
+// constant rounded to the format three ways, ordered so that each row reads
+// Down <= RNE <= Up.
+//
+// Down - toward -inf: the largest value not greater than the constant
+// RNE - to nearest, ties to even
+// Up - toward +inf: the smallest value not less than the constant
+//
+// No constant is exactly representable in these formats, and none lies exactly
+// halfway between two representable values, so RNE is unambiguous and
+// rmNearestTiesToAway agrees with it.
+struct MathConstantRoundings {
+ APFloat::MathConstant Constant;
+ const char *Name;
+ const char *Down;
+ const char *RNE;
+ const char *Up;
+};
+
+// clang-format off
+
+const MathConstantRoundings ConstantsBFloat[] = {
+ {APFloat::MathConstant::e, "e",
+ "0x1.5ap+1",
+ "0x1.5cp+1",
+ "0x1.5cp+1"},
+ {APFloat::MathConstant::log2e, "log2e",
+ "0x1.70p+0",
+ "0x1.72p+0",
+ "0x1.72p+0"},
+ {APFloat::MathConstant::log10e, "log10e",
+ "0x1.bcp-2",
+ "0x1.bcp-2",
+ "0x1.bep-2"},
+ {APFloat::MathConstant::pi, "pi",
+ "0x1.92p+1",
+ "0x1.92p+1",
+ "0x1.94p+1"},
+ {APFloat::MathConstant::inv_pi, "inv_pi",
+ "0x1.44p-2",
+ "0x1.46p-2",
+ "0x1.46p-2"},
+ {APFloat::MathConstant::inv_sqrtpi, "inv_sqrtpi",
+ "0x1.20p-1",
+ "0x1.20p-1",
+ "0x1.22p-1"},
+ {APFloat::MathConstant::ln2, "ln2",
+ "0x1.62p-1",
+ "0x1.62p-1",
+ "0x1.64p-1"},
+ {APFloat::MathConstant::ln10, "ln10",
+ "0x1.26p+1",
+ "0x1.26p+1",
+ "0x1.28p+1"},
+ {APFloat::MathConstant::sqrt2, "sqrt2",
+ "0x1.6ap+0",
+ "0x1.6ap+0",
+ "0x1.6cp+0"},
+ {APFloat::MathConstant::sqrt3, "sqrt3",
+ "0x1.bap+0",
+ "0x1.bcp+0",
+ "0x1.bcp+0"},
+ {APFloat::MathConstant::inv_sqrt3, "inv_sqrt3",
+ "0x1.26p-1",
+ "0x1.28p-1",
+ "0x1.28p-1"},
+ {APFloat::MathConstant::egamma, "egamma",
+ "0x1.26p-1",
+ "0x1.28p-1",
+ "0x1.28p-1"},
+ {APFloat::MathConstant::phi, "phi",
+ "0x1.9ep+0",
+ "0x1.9ep+0",
+ "0x1.a0p+0"},
+};
+
+const MathConstantRoundings ConstantsIEEEhalf[] = {
+ {APFloat::MathConstant::e, "e",
+ "0x1.5bcp+1",
+ "0x1.5c0p+1",
+ "0x1.5c0p+1"},
+ {APFloat::MathConstant::log2e, "log2e",
+ "0x1.714p+0",
+ "0x1.714p+0",
+ "0x1.718p+0"},
+ {APFloat::MathConstant::log10e, "log10e",
+ "0x1.bc8p-2",
+ "0x1.bccp-2",
+ "0x1.bccp-2"},
+ {APFloat::MathConstant::pi, "pi",
+ "0x1.920p+1",
+ "0x1.920p+1",
+ "0x1.924p+1"},
+ {APFloat::MathConstant::inv_pi, "inv_pi",
+ "0x1.45cp-2",
+ "0x1.460p-2",
+ "0x1.460p-2"},
+ {APFloat::MathConstant::inv_sqrtpi, "inv_sqrtpi",
+ "0x1.20cp-1",
+ "0x1.20cp-1",
+ "0x1.210p-1"},
+ {APFloat::MathConstant::ln2, "ln2",
+ "0x1.62cp-1",
+ "0x1.630p-1",
+ "0x1.630p-1"},
+ {APFloat::MathConstant::ln10, "ln10",
+ "0x1.268p+1",
+ "0x1.26cp+1",
+ "0x1.26cp+1"},
+ {APFloat::MathConstant::sqrt2, "sqrt2",
+ "0x1.6a0p+0",
+ "0x1.6a0p+0",
+ "0x1.6a4p+0"},
+ {APFloat::MathConstant::sqrt3, "sqrt3",
+ "0x1.bb4p+0",
+ "0x1.bb8p+0",
+ "0x1.bb8p+0"},
+ {APFloat::MathConstant::inv_sqrt3, "inv_sqrt3",
+ "0x1.278p-1",
+ "0x1.278p-1",
+ "0x1.27cp-1"},
+ {APFloat::MathConstant::egamma, "egamma",
+ "0x1.278p-1",
+ "0x1.278p-1",
+ "0x1.27cp-1"},
+ {APFloat::MathConstant::phi, "phi",
+ "0x1.9e0p+0",
+ "0x1.9e4p+0",
+ "0x1.9e4p+0"},
+};
+
+const MathConstantRoundings ConstantsIEEEsingle[] = {
+ {APFloat::MathConstant::e, "e",
+ "0x1.5bf0a8p+1",
+ "0x1.5bf0a8p+1",
+ "0x1.5bf0aap+1"},
+ {APFloat::MathConstant::log2e, "log2e",
+ "0x1.715476p+0",
+ "0x1.715476p+0",
+ "0x1.715478p+0"},
+ {APFloat::MathConstant::log10e, "log10e",
+ "0x1.bcb7b0p-2",
+ "0x1.bcb7b2p-2",
+ "0x1.bcb7b2p-2"},
+ {APFloat::MathConstant::pi, "pi",
+ "0x1.921fb4p+1",
+ "0x1.921fb6p+1",
+ "0x1.921fb6p+1"},
+ {APFloat::MathConstant::inv_pi, "inv_pi",
+ "0x1.45f306p-2",
+ "0x1.45f306p-2",
+ "0x1.45f308p-2"},
+ {APFloat::MathConstant::inv_sqrtpi, "inv_sqrtpi",
+ "0x1.20dd74p-1",
+ "0x1.20dd76p-1",
+ "0x1.20dd76p-1"},
+ {APFloat::MathConstant::ln2, "ln2",
+ "0x1.62e42ep-1",
+ "0x1.62e430p-1",
+ "0x1.62e430p-1"},
+ {APFloat::MathConstant::ln10, "ln10",
+ "0x1.26bb1ap+1",
+ "0x1.26bb1cp+1",
+ "0x1.26bb1cp+1"},
+ {APFloat::MathConstant::sqrt2, "sqrt2",
+ "0x1.6a09e6p+0",
+ "0x1.6a09e6p+0",
+ "0x1.6a09e8p+0"},
+ {APFloat::MathConstant::sqrt3, "sqrt3",
+ "0x1.bb67aep+0",
+ "0x1.bb67aep+0",
+ "0x1.bb67b0p+0"},
+ {APFloat::MathConstant::inv_sqrt3, "inv_sqrt3",
+ "0x1.279a74p-1",
+ "0x1.279a74p-1",
+ "0x1.279a76p-1"},
+ {APFloat::MathConstant::egamma, "egamma",
+ "0x1.2788cep-1",
+ "0x1.2788d0p-1",
+ "0x1.2788d0p-1"},
+ {APFloat::MathConstant::phi, "phi",
+ "0x1.9e3778p+0",
+ "0x1.9e377ap+0",
+ "0x1.9e377ap+0"},
+};
+
+const MathConstantRoundings ConstantsIEEEdouble[] = {
+ {APFloat::MathConstant::e, "e",
+ "0x1.5bf0a8b145769p+1",
+ "0x1.5bf0a8b145769p+1",
+ "0x1.5bf0a8b14576ap+1"},
+ {APFloat::MathConstant::log2e, "log2e",
+ "0x1.71547652b82fep+0",
+ "0x1.71547652b82fep+0",
+ "0x1.71547652b82ffp+0"},
+ {APFloat::MathConstant::log10e, "log10e",
+ "0x1.bcb7b1526e50ep-2",
+ "0x1.bcb7b1526e50ep-2",
+ "0x1.bcb7b1526e50fp-2"},
+ {APFloat::MathConstant::pi, "pi",
+ "0x1.921fb54442d18p+1",
+ "0x1.921fb54442d18p+1",
+ "0x1.921fb54442d19p+1"},
+ {APFloat::MathConstant::inv_pi, "inv_pi",
+ "0x1.45f306dc9c882p-2",
+ "0x1.45f306dc9c883p-2",
+ "0x1.45f306dc9c883p-2"},
+ {APFloat::MathConstant::inv_sqrtpi, "inv_sqrtpi",
+ "0x1.20dd750429b6dp-1",
+ "0x1.20dd750429b6dp-1",
+ "0x1.20dd750429b6ep-1"},
+ {APFloat::MathConstant::ln2, "ln2",
+ "0x1.62e42fefa39efp-1",
+ "0x1.62e42fefa39efp-1",
+ "0x1.62e42fefa39f0p-1"},
+ {APFloat::MathConstant::ln10, "ln10",
+ "0x1.26bb1bbb55515p+1",
+ "0x1.26bb1bbb55516p+1",
+ "0x1.26bb1bbb55516p+1"},
+ {APFloat::MathConstant::sqrt2, "sqrt2",
+ "0x1.6a09e667f3bccp+0",
+ "0x1.6a09e667f3bcdp+0",
+ "0x1.6a09e667f3bcdp+0"},
+ {APFloat::MathConstant::sqrt3, "sqrt3",
+ "0x1.bb67ae8584caap+0",
+ "0x1.bb67ae8584caap+0",
+ "0x1.bb67ae8584cabp+0"},
+ {APFloat::MathConstant::inv_sqrt3, "inv_sqrt3",
+ "0x1.279a74590331cp-1",
+ "0x1.279a74590331cp-1",
+ "0x1.279a74590331dp-1"},
+ {APFloat::MathConstant::egamma, "egamma",
+ "0x1.2788cfc6fb618p-1",
+ "0x1.2788cfc6fb619p-1",
+ "0x1.2788cfc6fb619p-1"},
+ {APFloat::MathConstant::phi, "phi",
+ "0x1.9e3779b97f4a7p+0",
+ "0x1.9e3779b97f4a8p+0",
+ "0x1.9e3779b97f4a8p+0"},
+};
+
+const MathConstantRoundings ConstantsX87DoubleExtended[] = {
+ {APFloat::MathConstant::e, "e",
+ "0x1.5bf0a8b145769534p+1",
+ "0x1.5bf0a8b145769536p+1",
+ "0x1.5bf0a8b145769536p+1"},
+ {APFloat::MathConstant::log2e, "log2e",
+ "0x1.71547652b82fe176p+0",
+ "0x1.71547652b82fe178p+0",
+ "0x1.71547652b82fe178p+0"},
+ {APFloat::MathConstant::log10e, "log10e",
+ "0x1.bcb7b1526e50e32ap-2",
+ "0x1.bcb7b1526e50e32ap-2",
+ "0x1.bcb7b1526e50e32cp-2"},
+ {APFloat::MathConstant::pi, "pi",
+ "0x1.921fb54442d18468p+1",
+ "0x1.921fb54442d1846ap+1",
+ "0x1.921fb54442d1846ap+1"},
+ {APFloat::MathConstant::inv_pi, "inv_pi",
+ "0x1.45f306dc9c882a52p-2",
+ "0x1.45f306dc9c882a54p-2",
+ "0x1.45f306dc9c882a54p-2"},
+ {APFloat::MathConstant::inv_sqrtpi, "inv_sqrtpi",
+ "0x1.20dd750429b6d11ap-1",
+ "0x1.20dd750429b6d11ap-1",
+ "0x1.20dd750429b6d11cp-1"},
+ {APFloat::MathConstant::ln2, "ln2",
+ "0x1.62e42fefa39ef356p-1",
+ "0x1.62e42fefa39ef358p-1",
+ "0x1.62e42fefa39ef358p-1"},
+ {APFloat::MathConstant::ln10, "ln10",
+ "0x1.26bb1bbb5551582cp+1",
+ "0x1.26bb1bbb5551582ep+1",
+ "0x1.26bb1bbb5551582ep+1"},
+ {APFloat::MathConstant::sqrt2, "sqrt2",
+ "0x1.6a09e667f3bcc908p+0",
+ "0x1.6a09e667f3bcc908p+0",
+ "0x1.6a09e667f3bcc90ap+0"},
+ {APFloat::MathConstant::sqrt3, "sqrt3",
+ "0x1.bb67ae8584caa73ap+0",
+ "0x1.bb67ae8584caa73cp+0",
+ "0x1.bb67ae8584caa73cp+0"},
+ {APFloat::MathConstant::inv_sqrt3, "inv_sqrt3",
+ "0x1.279a74590331c4d2p-1",
+ "0x1.279a74590331c4d2p-1",
+ "0x1.279a74590331c4d4p-1"},
+ {APFloat::MathConstant::egamma, "egamma",
+ "0x1.2788cfc6fb618f48p-1",
+ "0x1.2788cfc6fb618f4ap-1",
+ "0x1.2788cfc6fb618f4ap-1"},
+ {APFloat::MathConstant::phi, "phi",
+ "0x1.9e3779b97f4a7c14p+0",
+ "0x1.9e3779b97f4a7c16p+0",
+ "0x1.9e3779b97f4a7c16p+0"},
+};
+
+const MathConstantRoundings ConstantsIEEEquad[] = {
+ {APFloat::MathConstant::e, "e",
+ "0x1.5bf0a8b1457695355fb8ac404e7ap+1",
+ "0x1.5bf0a8b1457695355fb8ac404e7ap+1",
+ "0x1.5bf0a8b1457695355fb8ac404e7bp+1"},
+ {APFloat::MathConstant::log2e, "log2e",
+ "0x1.71547652b82fe1777d0ffda0d23ap+0",
+ "0x1.71547652b82fe1777d0ffda0d23ap+0",
+ "0x1.71547652b82fe1777d0ffda0d23bp+0"},
+ {APFloat::MathConstant::log10e, "log10e",
+ "0x1.bcb7b1526e50e32a6ab7555f5a67p-2",
+ "0x1.bcb7b1526e50e32a6ab7555f5a68p-2",
+ "0x1.bcb7b1526e50e32a6ab7555f5a68p-2"},
+ {APFloat::MathConstant::pi, "pi",
+ "0x1.921fb54442d18469898cc51701b8p+1",
+ "0x1.921fb54442d18469898cc51701b8p+1",
+ "0x1.921fb54442d18469898cc51701b9p+1"},
+ {APFloat::MathConstant::inv_pi, "inv_pi",
+ "0x1.45f306dc9c882a53f84eafa3ea69p-2",
+ "0x1.45f306dc9c882a53f84eafa3ea6ap-2",
+ "0x1.45f306dc9c882a53f84eafa3ea6ap-2"},
+ {APFloat::MathConstant::inv_sqrtpi, "inv_sqrtpi",
+ "0x1.20dd750429b6d11ae3a914fed7fdp-1",
+ "0x1.20dd750429b6d11ae3a914fed7fep-1",
+ "0x1.20dd750429b6d11ae3a914fed7fep-1"},
+ {APFloat::MathConstant::ln2, "ln2",
+ "0x1.62e42fefa39ef35793c7673007e5p-1",
+ "0x1.62e42fefa39ef35793c7673007e6p-1",
+ "0x1.62e42fefa39ef35793c7673007e6p-1"},
+ {APFloat::MathConstant::ln10, "ln10",
+ "0x1.26bb1bbb5551582dd4adac5705a6p+1",
+ "0x1.26bb1bbb5551582dd4adac5705a6p+1",
+ "0x1.26bb1bbb5551582dd4adac5705a7p+1"},
+ {APFloat::MathConstant::sqrt2, "sqrt2",
+ "0x1.6a09e667f3bcc908b2fb1366ea95p+0",
+ "0x1.6a09e667f3bcc908b2fb1366ea95p+0",
+ "0x1.6a09e667f3bcc908b2fb1366ea96p+0"},
+ {APFloat::MathConstant::sqrt3, "sqrt3",
+ "0x1.bb67ae8584caa73b25742d7078b8p+0",
+ "0x1.bb67ae8584caa73b25742d7078b8p+0",
+ "0x1.bb67ae8584caa73b25742d7078b9p+0"},
+ {APFloat::MathConstant::inv_sqrt3, "inv_sqrt3",
+ "0x1.279a74590331c4d218f81e4afb25p-1",
+ "0x1.279a74590331c4d218f81e4afb25p-1",
+ "0x1.279a74590331c4d218f81e4afb26p-1"},
+ {APFloat::MathConstant::egamma, "egamma",
+ "0x1.2788cfc6fb618f49a37c7f0202a5p-1",
+ "0x1.2788cfc6fb618f49a37c7f0202a6p-1",
+ "0x1.2788cfc6fb618f49a37c7f0202a6p-1"},
+ {APFloat::MathConstant::phi, "phi",
+ "0x1.9e3779b97f4a7c15f39cc0605cedp+0",
+ "0x1.9e3779b97f4a7c15f39cc0605ceep+0",
+ "0x1.9e3779b97f4a7c15f39cc0605ceep+0"},
+};
+
+const MathConstantRoundings ConstantsPPCDoubleDoubleLegacy[] = {
+ {APFloat::MathConstant::e, "e",
+ "0x1.5bf0a8b1457695355fb8ac404e0p+1",
+ "0x1.5bf0a8b1457695355fb8ac404e8p+1",
+ "0x1.5bf0a8b1457695355fb8ac404e8p+1"},
+ {APFloat::MathConstant::log2e, "log2e",
+ "0x1.71547652b82fe1777d0ffda0d20p+0",
+ "0x1.71547652b82fe1777d0ffda0d20p+0",
+ "0x1.71547652b82fe1777d0ffda0d28p+0"},
+ {APFloat::MathConstant::log10e, "log10e",
+ "0x1.bcb7b1526e50e32a6ab7555f5a0p-2",
+ "0x1.bcb7b1526e50e32a6ab7555f5a8p-2",
+ "0x1.bcb7b1526e50e32a6ab7555f5a8p-2"},
+ {APFloat::MathConstant::pi, "pi",
+ "0x1.921fb54442d18469898cc517018p+1",
+ "0x1.921fb54442d18469898cc517018p+1",
+ "0x1.921fb54442d18469898cc517020p+1"},
+ {APFloat::MathConstant::inv_pi, "inv_pi",
+ "0x1.45f306dc9c882a53f84eafa3ea0p-2",
+ "0x1.45f306dc9c882a53f84eafa3ea8p-2",
+ "0x1.45f306dc9c882a53f84eafa3ea8p-2"},
+ {APFloat::MathConstant::inv_sqrtpi, "inv_sqrtpi",
+ "0x1.20dd750429b6d11ae3a914fed78p-1",
+ "0x1.20dd750429b6d11ae3a914fed80p-1",
+ "0x1.20dd750429b6d11ae3a914fed80p-1"},
+ {APFloat::MathConstant::ln2, "ln2",
+ "0x1.62e42fefa39ef35793c76730078p-1",
+ "0x1.62e42fefa39ef35793c76730080p-1",
+ "0x1.62e42fefa39ef35793c76730080p-1"},
+ {APFloat::MathConstant::ln10, "ln10",
+ "0x1.26bb1bbb5551582dd4adac57058p+1",
+ "0x1.26bb1bbb5551582dd4adac57058p+1",
+ "0x1.26bb1bbb5551582dd4adac57060p+1"},
+ {APFloat::MathConstant::sqrt2, "sqrt2",
+ "0x1.6a09e667f3bcc908b2fb1366ea8p+0",
+ "0x1.6a09e667f3bcc908b2fb1366ea8p+0",
+ "0x1.6a09e667f3bcc908b2fb1366eb0p+0"},
+ {APFloat::MathConstant::sqrt3, "sqrt3",
+ "0x1.bb67ae8584caa73b25742d70788p+0",
+ "0x1.bb67ae8584caa73b25742d70788p+0",
+ "0x1.bb67ae8584caa73b25742d70790p+0"},
+ {APFloat::MathConstant::inv_sqrt3, "inv_sqrt3",
+ "0x1.279a74590331c4d218f81e4afb0p-1",
+ "0x1.279a74590331c4d218f81e4afb0p-1",
+ "0x1.279a74590331c4d218f81e4afb8p-1"},
+ {APFloat::MathConstant::egamma, "egamma",
+ "0x1.2788cfc6fb618f49a37c7f02028p-1",
+ "0x1.2788cfc6fb618f49a37c7f02028p-1",
+ "0x1.2788cfc6fb618f49a37c7f02030p-1"},
+ {APFloat::MathConstant::phi, "phi",
+ "0x1.9e3779b97f4a7c15f39cc0605c8p+0",
+ "0x1.9e3779b97f4a7c15f39cc0605d0p+0",
+ "0x1.9e3779b97f4a7c15f39cc0605d0p+0"},
+};
+
+const MathConstantRoundings ConstantsFloat6E3M2FN[] = {
+ {APFloat::MathConstant::e, "e",
+ "0x1.4p+1",
+ "0x1.4p+1",
+ "0x1.8p+1"},
+ {APFloat::MathConstant::pi, "pi",
+ "0x1.8p+1",
+ "0x1.8p+1",
+ "0x1.cp+1"},
+ {APFloat::MathConstant::inv_pi, "inv_pi",
+ "0x1.4p-2",
+ "0x1.4p-2",
+ "0x1.8p-2"},
+ {APFloat::MathConstant::egamma, "egamma",
+ "0x1.0p-1",
+ "0x1.4p-1",
+ "0x1.4p-1"},
+};
+
+// clang-format on
+
+} // namespace
+} // namespace llvm
+
+#endif
More information about the llvm-commits
mailing list