[libc++] Implement <numbers>

Summary: Constants have 33 significant decimal digits for IEEE 754 128-bit floating-point numbers.

Reviewers: ldionne, #libc, EricWF, zoecarver, curdeius

Reviewed By: ldionne, #libc, curdeius

Differential Revision: https://reviews.llvm.org/D77505
This commit is contained in:
Raul Tambre 2020-06-19 12:43:33 +05:30 committed by Kamlesh Kumar
parent bb48005660
commit 4f6c4b473c
16 changed files with 562 additions and 1 deletions

View File

@ -198,6 +198,8 @@ Status
------------------------------------------------- -----------------
``__cpp_lib_list_remove_return_type`` ``201806L``
------------------------------------------------- -----------------
``__cpp_lib_math_constants`` ``201907L``
------------------------------------------------- -----------------
``__cpp_lib_ranges`` *unimplemented*
------------------------------------------------- -----------------
``__cpp_lib_span`` ``202002L``

View File

@ -38,6 +38,8 @@ What's New in Libc++ 11.0.0?
New Features
------------
- ``<numbers>``
API Changes
-----------
- ...

View File

@ -117,6 +117,7 @@ set(files
module.modulemap
mutex
new
numbers
numeric
optional
ostream

View File

@ -378,6 +378,10 @@ module std [system] {
header "new"
export *
}
module numbers {
header "numbers"
export *
}
module numeric {
header "numeric"
export *

141
libcxx/include/numbers Normal file
View File

@ -0,0 +1,141 @@
// -*- C++ -*-
//===---------------------------- numbers ---------------------------------===//
//
// 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 _LIBCPP_NUMBERS
#define _LIBCPP_NUMBERS
/*
numbers synopsis
namespace std::numbers {
template<class T> inline constexpr T e_v = unspecified;
template<class T> inline constexpr T log2e_v = unspecified;
template<class T> inline constexpr T log10e_v = unspecified;
template<class T> inline constexpr T pi_v = unspecified;
template<class T> inline constexpr T inv_pi_v = unspecified;
template<class T> inline constexpr T inv_sqrtpi_v = unspecified;
template<class T> inline constexpr T ln2_v = unspecified;
template<class T> inline constexpr T ln10_v = unspecified;
template<class T> inline constexpr T sqrt2_v = unspecified;
template<class T> inline constexpr T sqrt3_v = unspecified;
template<class T> inline constexpr T inv_sqrt3_v = unspecified;
template<class T> inline constexpr T egamma_v = unspecified;
template<class T> inline constexpr T phi_v = unspecified;
template<floating_point T> inline constexpr T e_v<T> = see below;
template<floating_point T> inline constexpr T log2e_v<T> = see below;
template<floating_point T> inline constexpr T log10e_v<T> = see below;
template<floating_point T> inline constexpr T pi_v<T> = see below;
template<floating_point T> inline constexpr T inv_pi_v<T> = see below;
template<floating_point T> inline constexpr T inv_sqrtpi_v<T> = see below;
template<floating_point T> inline constexpr T ln2_v<T> = see below;
template<floating_point T> inline constexpr T ln10_v<T> = see below;
template<floating_point T> inline constexpr T sqrt2_v<T> = see below;
template<floating_point T> inline constexpr T sqrt3_v<T> = see below;
template<floating_point T> inline constexpr T inv_sqrt3_v<T> = see below;
template<floating_point T> inline constexpr T egamma_v<T> = see below;
template<floating_point T> inline constexpr T phi_v<T> = see below;
inline constexpr double e = e_v<double>;
inline constexpr double log2e = log2e_v<double>;
inline constexpr double log10e = log10e_v<double>;
inline constexpr double pi = pi_v<double>;
inline constexpr double inv_pi = inv_pi_v<double>;
inline constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
inline constexpr double ln2 = ln2_v<double>;
inline constexpr double ln10 = ln10_v<double>;
inline constexpr double sqrt2 = sqrt2_v<double>;
inline constexpr double sqrt3 = sqrt3_v<double>;
inline constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
inline constexpr double egamma = egamma_v<double>;
inline constexpr double phi = phi_v<double>;
}
*/
#include <__config>
#if _LIBCPP_STD_VER > 17
#include <type_traits>
#include <version>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
namespace numbers {
template <class T>
inline constexpr bool __false = false;
template <class T>
struct __illformed
{
static_assert(__false<T>, "A program that instantiates a primary template of a mathematical constant variable template is ill-formed.");
};
template <class T> inline constexpr T e_v = __illformed<T>{};
template <class T> inline constexpr T log2e_v = __illformed<T>{};
template <class T> inline constexpr T log10e_v = __illformed<T>{};
template <class T> inline constexpr T pi_v = __illformed<T>{};
template <class T> inline constexpr T inv_pi_v = __illformed<T>{};
template <class T> inline constexpr T inv_sqrtpi_v = __illformed<T>{};
template <class T> inline constexpr T ln2_v = __illformed<T>{};
template <class T> inline constexpr T ln10_v = __illformed<T>{};
template <class T> inline constexpr T sqrt2_v = __illformed<T>{};
template <class T> inline constexpr T sqrt3_v = __illformed<T>{};
template <class T> inline constexpr T inv_sqrt3_v = __illformed<T>{};
template <class T> inline constexpr T egamma_v = __illformed<T>{};
template <class T> inline constexpr T phi_v = __illformed<T>{};
template <class T>
concept __floating_point = std::is_floating_point_v<T>;
template <__floating_point T> inline constexpr T e_v<T> = 2.718281828459045235360287471352662;
template <__floating_point T> inline constexpr T log2e_v<T> = 1.442695040888963407359924681001892;
template <__floating_point T> inline constexpr T log10e_v<T> = 0.434294481903251827651128918916605;
template <__floating_point T> inline constexpr T pi_v<T> = 3.141592653589793238462643383279502;
template <__floating_point T> inline constexpr T inv_pi_v<T> = 0.318309886183790671537767526745028;
template <__floating_point T> inline constexpr T inv_sqrtpi_v<T> = 0.564189583547756286948079451560772;
template <__floating_point T> inline constexpr T ln2_v<T> = 0.693147180559945309417232121458176;
template <__floating_point T> inline constexpr T ln10_v<T> = 2.302585092994045684017991454684364;
template <__floating_point T> inline constexpr T sqrt2_v<T> = 1.414213562373095048801688724209698;
template <__floating_point T> inline constexpr T sqrt3_v<T> = 1.732050807568877293527446341505872;
template <__floating_point T> inline constexpr T inv_sqrt3_v<T> = 0.577350269189625764509148780501957;
template <__floating_point T> inline constexpr T egamma_v<T> = 0.577215664901532860606512090082402;
template <__floating_point T> inline constexpr T phi_v<T> = 1.618033988749894848204586834365638;
inline constexpr double e = e_v<double>;
inline constexpr double log2e = log2e_v<double>;
inline constexpr double log10e = log10e_v<double>;
inline constexpr double pi = pi_v<double>;
inline constexpr double inv_pi = inv_pi_v<double>;
inline constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
inline constexpr double ln2 = ln2_v<double>;
inline constexpr double ln10 = ln10_v<double>;
inline constexpr double sqrt2 = sqrt2_v<double>;
inline constexpr double sqrt3 = sqrt3_v<double>;
inline constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
inline constexpr double egamma = egamma_v<double>;
inline constexpr double phi = phi_v<double>;
} // namespace numbers
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif //_LIBCPP_STD_VER > 17
#endif // _LIBCPP_NUMBERS

View File

@ -75,6 +75,7 @@ __cpp_lib_make_from_tuple 201606L <tuple>
__cpp_lib_make_reverse_iterator 201402L <iterator>
__cpp_lib_make_unique 201304L <memory>
__cpp_lib_map_try_emplace 201411L <map>
__cpp_lib_math_constants 201907L <numbers>
__cpp_lib_math_special_functions 201603L <cmath>
__cpp_lib_memory_resource 201603L <memory_resource>
__cpp_lib_node_extract 201606L <map> <set> <unordered_map>
@ -237,6 +238,7 @@ __cpp_lib_void_t 201411L <type_traits>
# define __cpp_lib_is_constant_evaluated 201811L
# endif
# define __cpp_lib_list_remove_return_type 201806L
# define __cpp_lib_math_constants 201907L
// # define __cpp_lib_ranges 201811L
# define __cpp_lib_span 202002L
// # define __cpp_lib_three_way_comparison 201711L

View File

@ -97,6 +97,7 @@
#include <mutex>
#endif
#include <new>
#include <numbers>
#include <numeric>
#include <optional>
#include <ostream>

View File

@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// WARNING: This test was generated by generate_feature_test_macro_components.py
// and should not be edited manually.
// <numbers>
// Test the feature test macros defined by <numbers>
/* Constant Value
__cpp_lib_math_constants 201907L [C++2a]
*/
#include <numbers>
#include "test_macros.h"
#if TEST_STD_VER < 14
# ifdef __cpp_lib_math_constants
# error "__cpp_lib_math_constants should not be defined before c++2a"
# endif
#elif TEST_STD_VER == 14
# ifdef __cpp_lib_math_constants
# error "__cpp_lib_math_constants should not be defined before c++2a"
# endif
#elif TEST_STD_VER == 17
# ifdef __cpp_lib_math_constants
# error "__cpp_lib_math_constants should not be defined before c++2a"
# endif
#elif TEST_STD_VER > 17
# ifndef __cpp_lib_math_constants
# error "__cpp_lib_math_constants should be defined in c++2a"
# endif
# if __cpp_lib_math_constants != 201907L
# error "__cpp_lib_math_constants should have the value 201907L in c++2a"
# endif
#endif // TEST_STD_VER > 17
int main(int, char**) { return 0; }

View File

@ -67,6 +67,7 @@
__cpp_lib_make_reverse_iterator 201402L [C++14]
__cpp_lib_make_unique 201304L [C++14]
__cpp_lib_map_try_emplace 201411L [C++17]
__cpp_lib_math_constants 201907L [C++2a]
__cpp_lib_math_special_functions 201603L [C++17]
__cpp_lib_memory_resource 201603L [C++17]
__cpp_lib_node_extract 201606L [C++17]
@ -317,6 +318,10 @@
# error "__cpp_lib_map_try_emplace should not be defined before c++17"
# endif
# ifdef __cpp_lib_math_constants
# error "__cpp_lib_math_constants should not be defined before c++2a"
# endif
# ifdef __cpp_lib_math_special_functions
# error "__cpp_lib_math_special_functions should not be defined before c++17"
# endif
@ -693,6 +698,10 @@
# error "__cpp_lib_map_try_emplace should not be defined before c++17"
# endif
# ifdef __cpp_lib_math_constants
# error "__cpp_lib_math_constants should not be defined before c++2a"
# endif
# ifdef __cpp_lib_math_special_functions
# error "__cpp_lib_math_special_functions should not be defined before c++17"
# endif
@ -1231,6 +1240,10 @@
# error "__cpp_lib_map_try_emplace should have the value 201411L in c++17"
# endif
# ifdef __cpp_lib_math_constants
# error "__cpp_lib_math_constants should not be defined before c++2a"
# endif
# if !defined(_LIBCPP_VERSION)
# ifndef __cpp_lib_math_special_functions
# error "__cpp_lib_math_special_functions should be defined in c++17"
@ -1967,6 +1980,13 @@
# error "__cpp_lib_map_try_emplace should have the value 201411L in c++2a"
# endif
# ifndef __cpp_lib_math_constants
# error "__cpp_lib_math_constants should be defined in c++2a"
# endif
# if __cpp_lib_math_constants != 201907L
# error "__cpp_lib_math_constants should have the value 201907L in c++2a"
# endif
# if !defined(_LIBCPP_VERSION)
# ifndef __cpp_lib_math_special_functions
# error "__cpp_lib_math_special_functions should be defined in c++2a"

View File

@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
#include <numbers>
// We are testing if these are defined by taking an address. Don't care if the result is unused.
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wunused-variable"
#endif
constexpr bool tests() {
const double* dd0{&std::numbers::e};
const double* dd1{&std::numbers::log2e};
const double* dd2{&std::numbers::log10e};
const double* dd3{&std::numbers::pi};
const double* dd4{&std::numbers::inv_pi};
const double* dd5{&std::numbers::inv_sqrtpi};
const double* dd6{&std::numbers::ln2};
const double* dd7{&std::numbers::ln10};
const double* dd8{&std::numbers::sqrt2};
const double* dd9{&std::numbers::sqrt3};
const double* dd10{&std::numbers::inv_sqrt3};
const double* dd11{&std::numbers::egamma};
const double* dd12{&std::numbers::phi};
const float* f0{&std::numbers::e_v<float>};
const float* f1{&std::numbers::log2e_v<float>};
const float* f2{&std::numbers::log10e_v<float>};
const float* f3{&std::numbers::pi_v<float>};
const float* f4{&std::numbers::inv_pi_v<float>};
const float* f5{&std::numbers::inv_sqrtpi_v<float>};
const float* f6{&std::numbers::ln2_v<float>};
const float* f7{&std::numbers::ln10_v<float>};
const float* f8{&std::numbers::sqrt2_v<float>};
const float* f9{&std::numbers::sqrt3_v<float>};
const float* f10{&std::numbers::inv_sqrt3_v<float>};
const float* f11{&std::numbers::egamma_v<float>};
const float* f12{&std::numbers::phi_v<float>};
const double* d0{&std::numbers::e_v<double>};
const double* d1{&std::numbers::log2e_v<double>};
const double* d2{&std::numbers::log10e_v<double>};
const double* d3{&std::numbers::pi_v<double>};
const double* d4{&std::numbers::inv_pi_v<double>};
const double* d5{&std::numbers::inv_sqrtpi_v<double>};
const double* d6{&std::numbers::ln2_v<double>};
const double* d7{&std::numbers::ln10_v<double>};
const double* d8{&std::numbers::sqrt2_v<double>};
const double* d9{&std::numbers::sqrt3_v<double>};
const double* d10{&std::numbers::inv_sqrt3_v<double>};
const double* d11{&std::numbers::egamma_v<double>};
const double* d12{&std::numbers::phi_v<double>};
const long double* ld0{&std::numbers::e_v<long double>};
const long double* ld1{&std::numbers::log2e_v<long double>};
const long double* ld2{&std::numbers::log10e_v<long double>};
const long double* ld3{&std::numbers::pi_v<long double>};
const long double* ld4{&std::numbers::inv_pi_v<long double>};
const long double* ld5{&std::numbers::inv_sqrtpi_v<long double>};
const long double* ld6{&std::numbers::ln2_v<long double>};
const long double* ld7{&std::numbers::ln10_v<long double>};
const long double* ld8{&std::numbers::sqrt2_v<long double>};
const long double* ld9{&std::numbers::sqrt3_v<long double>};
const long double* ld10{&std::numbers::inv_sqrt3_v<long double>};
const long double* ld11{&std::numbers::egamma_v<long double>};
const long double* ld12{&std::numbers::phi_v<long double>};
return true;
}
static_assert(tests());
int main() { tests(); }

View File

@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
#include <numbers>
// Initializing the primary template is ill-formed.
int log2e{std::numbers::log2e_v<
int>}; // expected-error-re@numbers:* {{static_assert failed {{.*}} "A program that instantiates a primary template of a mathematical constant variable template is ill-formed."}}
int log10e{std::numbers::log10e_v<int>};
int pi{std::numbers::pi_v<int>};
int inv_pi{std::numbers::inv_pi_v<int>};
int inv_sqrtpi{std::numbers::inv_sqrtpi_v<int>};
int ln2{std::numbers::ln2_v<int>};
int ln10{std::numbers::ln10_v<int>};
int sqrt2{std::numbers::sqrt2_v<int>};
int sqrt3{std::numbers::sqrt3_v<int>};
int inv_sqrt3{std::numbers::inv_sqrt3_v<int>};
int egamma{std::numbers::egamma_v<int>};
int phi{std::numbers::phi_v<int>};
int main() { return 0; }

View File

@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
#include <cassert>
#include <numbers>
// We are testing if template instantiation works. Don't care if the result is unused.
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wunused-variable"
#endif
constexpr bool tests() {
float f0{std::numbers::e_v<float>};
float f1{std::numbers::log2e_v<float>};
float f2{std::numbers::log10e_v<float>};
float f3{std::numbers::pi_v<float>};
float f4{std::numbers::inv_pi_v<float>};
float f5{std::numbers::inv_sqrtpi_v<float>};
float f6{std::numbers::ln2_v<float>};
float f7{std::numbers::ln10_v<float>};
float f8{std::numbers::sqrt2_v<float>};
float f9{std::numbers::sqrt3_v<float>};
float f10{std::numbers::inv_sqrt3_v<float>};
float f11{std::numbers::egamma_v<float>};
float f12{std::numbers::phi_v<float>};
double d0{std::numbers::e_v<double>};
double d1{std::numbers::log2e_v<double>};
double d2{std::numbers::log10e_v<double>};
double d3{std::numbers::pi_v<double>};
double d4{std::numbers::inv_pi_v<double>};
double d5{std::numbers::inv_sqrtpi_v<double>};
double d6{std::numbers::ln2_v<double>};
double d7{std::numbers::ln10_v<double>};
double d8{std::numbers::sqrt2_v<double>};
double d9{std::numbers::sqrt3_v<double>};
double d10{std::numbers::inv_sqrt3_v<double>};
double d11{std::numbers::egamma_v<double>};
double d12{std::numbers::phi_v<double>};
assert(d0 == std::numbers::e);
assert(d1 == std::numbers::log2e);
assert(d2 == std::numbers::log10e);
assert(d3 == std::numbers::pi);
assert(d4 == std::numbers::inv_pi);
assert(d5 == std::numbers::inv_sqrtpi);
assert(d6 == std::numbers::ln2);
assert(d7 == std::numbers::ln10);
assert(d8 == std::numbers::sqrt2);
assert(d9 == std::numbers::sqrt3);
assert(d10 == std::numbers::inv_sqrt3);
assert(d11 == std::numbers::egamma);
assert(d12 == std::numbers::phi);
long double ld0{std::numbers::e_v<long double>};
long double ld1{std::numbers::log2e_v<long double>};
long double ld2{std::numbers::log10e_v<long double>};
long double ld3{std::numbers::pi_v<long double>};
long double ld4{std::numbers::inv_pi_v<long double>};
long double ld5{std::numbers::inv_sqrtpi_v<long double>};
long double ld6{std::numbers::ln2_v<long double>};
long double ld7{std::numbers::ln10_v<long double>};
long double ld8{std::numbers::sqrt2_v<long double>};
long double ld9{std::numbers::sqrt3_v<long double>};
long double ld10{std::numbers::inv_sqrt3_v<long double>};
long double ld11{std::numbers::egamma_v<long double>};
long double ld12{std::numbers::phi_v<long double>};
return true;
}
static_assert(tests());
int main() { tests(); }

View File

@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
#include <numbers>
struct user {
int value;
};
template <>
user std::numbers::e_v<user>{};
template <>
user std::numbers::log2e_v<user>{};
template <>
user std::numbers::log10e_v<user>{};
template <>
user std::numbers::pi_v<user>{};
template <>
user std::numbers::inv_pi_v<user>{};
template <>
user std::numbers::inv_sqrtpi_v<user>{};
template <>
user std::numbers::ln2_v<user>{};
template <>
user std::numbers::ln10_v<user>{};
template <>
user std::numbers::sqrt2_v<user>{};
template <>
user std::numbers::sqrt3_v<user>{};
template <>
user std::numbers::inv_sqrt3_v<user>{};
template <>
user std::numbers::egamma_v<user>{};
template <>
user std::numbers::phi_v<user>{};
int main() { return 0; }

View File

@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
#include <cassert>
#include <numbers>
constexpr bool tests() {
assert(std::numbers::e == 0x1.5bf0a8b145769p+1);
assert(std::numbers::e_v<double> == 0x1.5bf0a8b145769p+1);
assert(std::numbers::e_v<long double> == 0x1.5bf0a8b145769p+1l);
assert(std::numbers::e_v<float> == 0x1.5bf0a8p+1f);
assert(std::numbers::log2e == 0x1.71547652b82fep+0);
assert(std::numbers::log2e_v<double> == 0x1.71547652b82fep+0);
assert(std::numbers::log2e_v<long double> == 0x1.71547652b82fep+0l);
assert(std::numbers::log2e_v<float> == 0x1.715476p+0f);
assert(std::numbers::log10e == 0x1.bcb7b1526e50ep-2);
assert(std::numbers::log10e_v<double> == 0x1.bcb7b1526e50ep-2);
assert(std::numbers::log10e_v<long double> == 0x1.bcb7b1526e50ep-2l);
assert(std::numbers::log10e_v<float> == 0x1.bcb7b15p-2f);
assert(std::numbers::pi == 0x1.921fb54442d18p+1);
assert(std::numbers::pi_v<double> == 0x1.921fb54442d18p+1);
assert(std::numbers::pi_v<long double> == 0x1.921fb54442d18p+1l);
assert(std::numbers::pi_v<float> == 0x1.921fb54p+1f);
assert(std::numbers::inv_pi == 0x1.45f306dc9c883p-2);
assert(std::numbers::inv_pi_v<double> == 0x1.45f306dc9c883p-2);
assert(std::numbers::inv_pi_v<long double> == 0x1.45f306dc9c883p-2l);
assert(std::numbers::inv_pi_v<float> == 0x1.45f306p-2f);
assert(std::numbers::inv_sqrtpi == 0x1.20dd750429b6dp-1);
assert(std::numbers::inv_sqrtpi_v<double> == 0x1.20dd750429b6dp-1);
assert(std::numbers::inv_sqrtpi_v<long double> == 0x1.20dd750429b6dp-1l);
assert(std::numbers::inv_sqrtpi_v<float> == 0x1.20dd76p-1f);
assert(std::numbers::ln2 == 0x1.62e42fefa39efp-1);
assert(std::numbers::ln2_v<double> == 0x1.62e42fefa39efp-1);
assert(std::numbers::ln2_v<long double> == 0x1.62e42fefa39efp-1l);
assert(std::numbers::ln2_v<float> == 0x1.62e42fp-1f);
assert(std::numbers::ln10 == 0x1.26bb1bbb55516p+1);
assert(std::numbers::ln10_v<double> == 0x1.26bb1bbb55516p+1);
assert(std::numbers::ln10_v<long double> == 0x1.26bb1bbb55516p+1l);
assert(std::numbers::ln10_v<float> == 0x1.26bb1bp+1f);
assert(std::numbers::sqrt2 == 0x1.6a09e667f3bcdp+0);
assert(std::numbers::sqrt2_v<double> == 0x1.6a09e667f3bcdp+0);
assert(std::numbers::sqrt2_v<long double> == 0x1.6a09e667f3bcdp+0l);
assert(std::numbers::sqrt2_v<float> == 0x1.6a09e6p+0f);
assert(std::numbers::sqrt3 == 0x1.bb67ae8584caap+0);
assert(std::numbers::sqrt3_v<double> == 0x1.bb67ae8584caap+0);
assert(std::numbers::sqrt3_v<long double> == 0x1.bb67ae8584caap+0l);
assert(std::numbers::sqrt3_v<float> == 0x1.bb67aep+0f);
assert(std::numbers::inv_sqrt3 == 0x1.279a74590331cp-1);
assert(std::numbers::inv_sqrt3_v<double> == 0x1.279a74590331cp-1);
assert(std::numbers::inv_sqrt3_v<long double> == 0x1.279a74590331cp-1l);
assert(std::numbers::inv_sqrt3_v<float> == 0x1.279a74p-1f);
assert(std::numbers::egamma == 0x1.2788cfc6fb619p-1);
assert(std::numbers::egamma_v<double> == 0x1.2788cfc6fb619p-1);
assert(std::numbers::egamma_v<long double> == 0x1.2788cfc6fb619p-1l);
assert(std::numbers::egamma_v<float> == 0x1.2788cfp-1f);
assert(std::numbers::phi == 0x1.9e3779b97f4a8p+0);
assert(std::numbers::phi_v<double> == 0x1.9e3779b97f4a8p+0);
assert(std::numbers::phi_v<long double> == 0x1.9e3779b97f4a8p+0l);
assert(std::numbers::phi_v<float> == 0x1.9e3779ap+0f);
return true;
}
static_assert(tests());
int main() { tests(); }

View File

@ -599,6 +599,12 @@ feature_test_macros = sorted([ add_version_header(x) for x in [
},
"headers": ["span"],
},
{"name": "__cpp_lib_math_constants",
"values": {
"c++2a": int(201907),
},
"headers": ["numbers"],
},
]], key=lambda tc: tc["name"])
def get_std_dialects():

View File

@ -161,7 +161,7 @@
<tr><td><a href="https://wg21.link/P0408">P0408</a></td><td>LWG</td><td>Efficient Access to basic_stringbuf s Buffer</td><td>Cologne</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0466">P0466</a></td><td>LWG</td><td>Layout-compatibility and Pointer-interconvertibility Traits</td><td>Cologne</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0553">P0553</a></td><td>LWG</td><td>Bit operations</td><td>Cologne</td><td>Complete</td><td>9.0</td></tr>
<tr><td><a href="https://wg21.link/P0631">P0631</a></td><td>LWG</td><td>Math Constants</td><td>Cologne</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0631">P0631</a></td><td>LWG</td><td>Math Constants</td><td>Cologne</td><td>Complete</td><td>11.0</td></tr>
<tr><td><a href="https://wg21.link/P0645">P0645</a></td><td>LWG</td><td>Text Formatting</td><td>Cologne</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0660">P0660</a></td><td>LWG</td><td>Stop Token and Joining Thread, Rev 10</td><td>Cologne</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0784">P0784</a></td><td>CWG</td><td>More constexpr containers</td><td>Cologne</td><td></td><td></td></tr>