diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -38,6 +38,8 @@ New Features ------------ +- ```` + API Changes ----------- - ... diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -116,6 +116,7 @@ module.modulemap mutex new + numbers numeric optional ostream diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -374,6 +374,10 @@ header "new" export * } + module numbers { + header "numbers" + export * + } module numeric { header "numeric" export * diff --git a/libcxx/include/numbers b/libcxx/include/numbers new file mode 100644 --- /dev/null +++ b/libcxx/include/numbers @@ -0,0 +1,112 @@ +// -*- 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 inline constexpr T e_v = unspecified; + template inline constexpr T log2e_v = unspecified; + template inline constexpr T log10e_v = unspecified; + template inline constexpr T pi_v = unspecified; + template inline constexpr T inv_pi_v = unspecified; + template inline constexpr T inv_sqrtpi_v = unspecified; + template inline constexpr T ln2_v = unspecified; + template inline constexpr T ln10_v = unspecified; + template inline constexpr T sqrt2_v = unspecified; + template inline constexpr T sqrt3_v = unspecified; + template inline constexpr T inv_sqrt3_v = unspecified; + template inline constexpr T egamma_v = unspecified; + template inline constexpr T phi_v = unspecified; + + template inline constexpr T e_v = see below; + template inline constexpr T log2e_v = see below; + template inline constexpr T log10e_v = see below; + template inline constexpr T pi_v = see below; + template inline constexpr T inv_pi_v = see below; + template inline constexpr T inv_sqrtpi_v = see below; + template inline constexpr T ln2_v = see below; + template inline constexpr T ln10_v = see below; + template inline constexpr T sqrt2_v = see below; + template inline constexpr T sqrt3_v = see below; + template inline constexpr T inv_sqrt3_v = see below; + template inline constexpr T egamma_v = see below; + template inline constexpr T phi_v = see below; + + inline constexpr double e = e_v; + inline constexpr double log2e = log2e_v; + inline constexpr double log10e = log10e_v; + inline constexpr double pi = pi_v; + inline constexpr double inv_pi = inv_pi_v; + inline constexpr double inv_sqrtpi = inv_sqrtpi_v; + inline constexpr double ln2 = ln2_v; + inline constexpr double ln10 = ln10_v; + inline constexpr double sqrt2 = sqrt2_v; + inline constexpr double sqrt3 = sqrt3_v; + inline constexpr double inv_sqrt3 = inv_sqrt3_v; + inline constexpr double egamma = egamma_v; + inline constexpr double phi = phi_v; +} +*/ + +#include <__config> +#include + +#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 +concept floating_point = std::is_floating_point_v; + +template inline constexpr T e_v = 2.718281828459045235360287471352662; +template inline constexpr T log2e_v = 1.442695040888963407359924681001892; +template inline constexpr T log10e_v = 0.434294481903251827651128918916605; +template inline constexpr T pi_v = 3.141592653589793238462643383279502; +template inline constexpr T inv_pi_v = 0.318309886183790671537767526745028; +template inline constexpr T inv_sqrtpi_v = 0.564189583547756286948079451560772; +template inline constexpr T ln2_v = 0.693147180559945309417232121458176; +template inline constexpr T ln10_v = 2.302585092994045684017991454684364; +template inline constexpr T sqrt2_v = 1.414213562373095048801688724209698; +template inline constexpr T sqrt3_v = 1.732050807568877293527446341505872; +template inline constexpr T inv_sqrt3_v = 0.577350269189625764509148780501957; +template inline constexpr T egamma_v = 0.577215664901532860606512090082402; +template inline constexpr T phi_v = 1.618033988749894848204586834365638; + +inline constexpr double e = e_v; +inline constexpr double log2e = log2e_v; +inline constexpr double log10e = log10e_v; +inline constexpr double pi = pi_v; +inline constexpr double inv_pi = inv_pi_v; +inline constexpr double inv_sqrtpi = inv_sqrtpi_v; +inline constexpr double ln2 = ln2_v; +inline constexpr double ln10 = ln10_v; +inline constexpr double sqrt2 = sqrt2_v; +inline constexpr double sqrt3 = sqrt3_v; +inline constexpr double inv_sqrt3 = inv_sqrt3_v; +inline constexpr double egamma = egamma_v; +inline constexpr double phi = phi_v; + +} // namespace numbers + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_NUMBERS diff --git a/libcxx/test/std/numerics/numbers/non_floating_point.fail.cpp b/libcxx/test/std/numerics/numbers/non_floating_point.fail.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/numerics/numbers/non_floating_point.fail.cpp @@ -0,0 +1,30 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +#include + +int e{std::numbers::e_v}; +int log2e{std::numbers::log2e_v}; +int log10e{std::numbers::log10e_v}; +int pi{std::numbers::pi_v}; +int inv_pi{std::numbers::inv_pi_v}; +int inv_sqrtpi{std::numbers::inv_sqrtpi_v}; +int ln2{std::numbers::ln2_v}; +int ln10{std::numbers::ln10_v}; +int sqrt2{std::numbers::sqrt2_v}; +int sqrt3{std::numbers::sqrt3_v}; +int inv_sqrt3{std::numbers::inv_sqrt3_v}; +int egamma{std::numbers::egamma_v}; +int phi{std::numbers::phi_v}; + +int main() +{ + return 0; +} diff --git a/libcxx/test/std/numerics/numbers/user_type.pass.cpp b/libcxx/test/std/numerics/numbers/user_type.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/numerics/numbers/user_type.pass.cpp @@ -0,0 +1,35 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +#include + +struct user_type +{ + long double a; +}; + +user_type e{std::numbers::e_v}; +user_type log2e{std::numbers::log2e_v}; +user_type log10e{std::numbers::log10e_v}; +user_type pi{std::numbers::pi_v}; +user_type inv_pi{std::numbers::inv_pi_v}; +user_type inv_sqrtpi{std::numbers::inv_sqrtpi_v}; +user_type ln2{std::numbers::ln2_v}; +user_type ln10{std::numbers::ln10_v}; +user_type sqrt2{std::numbers::sqrt2_v}; +user_type sqrt3{std::numbers::sqrt3_v}; +user_type inv_sqrt3{std::numbers::inv_sqrt3_v}; +user_type egamma{std::numbers::egamma_v}; +user_type phi{std::numbers::phi_v}; + +int main() +{ + return 0; +} diff --git a/libcxx/www/cxx2a_status.html b/libcxx/www/cxx2a_status.html --- a/libcxx/www/cxx2a_status.html +++ b/libcxx/www/cxx2a_status.html @@ -161,7 +161,7 @@ P0408LWGEfficient Access to basic_stringbuf ’s BufferCologne P0466LWGLayout-compatibility and Pointer-interconvertibility TraitsCologne P0553LWGBit operationsCologneComplete9.0 - P0631LWGMath ConstantsCologne + P0631LWGMath ConstantsCologneComplete11.0 P0645LWGText FormattingCologne P0660LWGStop Token and Joining Thread, Rev 10Cologne P0784CWGMore constexpr containersCologne