-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement <numbers> Math Constants #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0dc6ced
Implement <numbers> Math Constants
SuperWig 6b3903c
Add floating_point concept
SuperWig 43bdaae
Add warning supressions
SuperWig 89f59e3
Add comments and newline
SuperWig 50eebc0
Remove whitespace
SuperWig f8ff577
Use to_chars for values
SuperWig 4591643
Provide primary template and specialise floating point types
SuperWig 9d256c1
Remove unused header
SuperWig 92b26c4
Improve wording and formatting of _Invalid
SuperWig d97ed66
Remove unnecessary casts
SuperWig fa8140a
Formatting
SuperWig 1e53041
Merge branch 'master' into numbers
StephanTLavavej 701da46
Include xstddef for _Always_false. Adjust formatting.
StephanTLavavej 48d9cad
Update __msvc_all_public_headers.hpp.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| // numbers standard header (core) | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #pragma once | ||
| #ifndef _NUMBERS_ | ||
| #define _NUMBERS_ | ||
| #include <yvals_core.h> | ||
| #if _STL_COMPILER_PREPROCESSOR | ||
| #if !_HAS_CXX20 | ||
| #pragma message("The contents of <numbers> are available only with C++20 or later.") | ||
| #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv | ||
| #ifdef __cpp_lib_concepts | ||
| #include <concepts> | ||
| #else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv | ||
| #include <xstddef> | ||
| #endif // ^^^ !defined(__cpp_lib_concepts) ^^^ | ||
|
|
||
| #pragma pack(push, _CRT_PACKING) | ||
| #pragma warning(push, _STL_WARNING_LEVEL) | ||
| #pragma warning(disable : _STL_DISABLED_WARNINGS) | ||
| _STL_DISABLE_CLANG_WARNINGS | ||
| #pragma push_macro("new") | ||
| #undef new | ||
|
|
||
| _STD_BEGIN | ||
| namespace numbers { | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| template <class _Ty> | ||
| struct _Invalid { | ||
| static_assert(_Always_false<_Ty>, "A program that instantiates a primary template of a mathematical constant " | ||
CaseyCarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "variable template is ill-formed. (N4835 [math.constants]/3)"); | ||
| }; | ||
SuperWig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| template <class _Ty> | ||
| inline constexpr _Ty e_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty log2e_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty log10e_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty pi_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty inv_pi_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty inv_sqrtpi_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty ln2_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty ln10_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty sqrt2_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty sqrt3_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty inv_sqrt3_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty egamma_v = _Invalid<_Ty>{}; | ||
| template <class _Ty> | ||
| inline constexpr _Ty phi_v = _Invalid<_Ty>{}; | ||
|
|
||
| #ifdef __cpp_lib_concepts | ||
SuperWig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| template <floating_point _Floating> | ||
SuperWig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| inline constexpr _Floating e_v<_Floating> = static_cast<_Floating>(2.718281828459045); | ||
SuperWig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| template <floating_point _Floating> | ||
| inline constexpr _Floating log2e_v<_Floating> = static_cast<_Floating>(1.4426950408889634); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating log10e_v<_Floating> = static_cast<_Floating>(0.4342944819032518); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating pi_v<_Floating> = static_cast<_Floating>(3.141592653589793); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating inv_pi_v<_Floating> = static_cast<_Floating>(0.3183098861837907); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating inv_sqrtpi_v<_Floating> = static_cast<_Floating>(0.5641895835477563); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating ln2_v<_Floating> = static_cast<_Floating>(0.6931471805599453); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating ln10_v<_Floating> = static_cast<_Floating>(2.302585092994046); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating sqrt2_v<_Floating> = static_cast<_Floating>(1.4142135623730951); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating sqrt3_v<_Floating> = static_cast<_Floating>(1.7320508075688772); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating inv_sqrt3_v<_Floating> = static_cast<_Floating>(0.5773502691896257); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating egamma_v<_Floating> = static_cast<_Floating>(0.5772156649015329); | ||
| template <floating_point _Floating> | ||
| inline constexpr _Floating phi_v<_Floating> = static_cast<_Floating>(1.618033988749895); | ||
| #else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv | ||
| template <> | ||
| inline constexpr double e_v<double> = 2.718281828459045; | ||
| template <> | ||
| inline constexpr double log2e_v<double> = 1.4426950408889634; | ||
| template <> | ||
| inline constexpr double log10e_v<double> = 0.4342944819032518; | ||
| template <> | ||
| inline constexpr double pi_v<double> = 3.141592653589793; | ||
| template <> | ||
| inline constexpr double inv_pi_v<double> = 0.3183098861837907; | ||
| template <> | ||
| inline constexpr double inv_sqrtpi_v<double> = 0.5641895835477563; | ||
| template <> | ||
| inline constexpr double ln2_v<double> = 0.6931471805599453; | ||
| template <> | ||
| inline constexpr double ln10_v<double> = 2.302585092994046; | ||
| template <> | ||
| inline constexpr double sqrt2_v<double> = 1.4142135623730951; | ||
| template <> | ||
| inline constexpr double sqrt3_v<double> = 1.7320508075688772; | ||
| template <> | ||
| inline constexpr double inv_sqrt3_v<double> = 0.5773502691896257; | ||
| template <> | ||
| inline constexpr double egamma_v<double> = 0.5772156649015329; | ||
| template <> | ||
| inline constexpr double phi_v<double> = 1.618033988749895; | ||
|
|
||
| template <> | ||
| inline constexpr float e_v<float> = static_cast<float>(e_v<double>); | ||
| template <> | ||
| inline constexpr float log2e_v<float> = static_cast<float>(log2e_v<double>); | ||
| template <> | ||
| inline constexpr float log10e_v<float> = static_cast<float>(log10e_v<double>); | ||
| template <> | ||
| inline constexpr float pi_v<float> = static_cast<float>(pi_v<double>); | ||
| template <> | ||
| inline constexpr float inv_pi_v<float> = static_cast<float>(inv_pi_v<double>); | ||
| template <> | ||
| inline constexpr float inv_sqrtpi_v<float> = static_cast<float>(inv_sqrtpi_v<double>); | ||
| template <> | ||
| inline constexpr float ln2_v<float> = static_cast<float>(ln2_v<double>); | ||
| template <> | ||
| inline constexpr float ln10_v<float> = static_cast<float>(ln10_v<double>); | ||
| template <> | ||
| inline constexpr float sqrt2_v<float> = static_cast<float>(sqrt2_v<double>); | ||
| template <> | ||
| inline constexpr float sqrt3_v<float> = static_cast<float>(sqrt3_v<double>); | ||
| template <> | ||
| inline constexpr float inv_sqrt3_v<float> = static_cast<float>(inv_sqrt3_v<double>); | ||
| template <> | ||
| inline constexpr float egamma_v<float> = static_cast<float>(egamma_v<double>); | ||
| template <> | ||
| inline constexpr float phi_v<float> = static_cast<float>(phi_v<double>); | ||
|
|
||
| template <> | ||
| inline constexpr long double e_v<long double> = e_v<double>; | ||
| template <> | ||
| inline constexpr long double log2e_v<long double> = log2e_v<double>; | ||
| template <> | ||
| inline constexpr long double log10e_v<long double> = log10e_v<double>; | ||
| template <> | ||
| inline constexpr long double pi_v<long double> = pi_v<double>; | ||
| template <> | ||
| inline constexpr long double inv_pi_v<long double> = inv_pi_v<double>; | ||
| template <> | ||
| inline constexpr long double inv_sqrtpi_v<long double> = inv_sqrtpi_v<double>; | ||
| template <> | ||
| inline constexpr long double ln2_v<long double> = ln2_v<double>; | ||
| template <> | ||
| inline constexpr long double ln10_v<long double> = ln10_v<double>; | ||
| template <> | ||
| inline constexpr long double sqrt2_v<long double> = sqrt2_v<double>; | ||
| template <> | ||
| inline constexpr long double sqrt3_v<long double> = sqrt3_v<double>; | ||
| template <> | ||
| inline constexpr long double inv_sqrt3_v<long double> = inv_sqrt3_v<double>; | ||
| template <> | ||
| inline constexpr long double egamma_v<long double> = egamma_v<double>; | ||
| template <> | ||
| inline constexpr long double phi_v<long double> = phi_v<double>; | ||
| #endif // ^^^ !defined(__cpp_lib_concepts) ^^^ | ||
CaseyCarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
| _STD_END | ||
|
|
||
| #pragma pop_macro("new") | ||
| _STL_RESTORE_CLANG_WARNINGS | ||
| #pragma warning(pop) | ||
| #pragma pack(pop) | ||
| #endif // _HAS_CXX20 | ||
| #endif // _STL_COMPILER_PREPROCESSOR | ||
| #endif // _NUMBERS_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.