| // Copyright 2017-2020 The Khronos Group. This work is licensed under a |
| // Creative Commons Attribution 4.0 International License; see |
| // http://creativecommons.org/licenses/by/4.0/ |
| |
| [[math-constants-library]] |
| === Math Constants Library |
| |
| OpenCL {cpp} implements math constant library. |
| The purpose of this library is to provide the commonly used constants for half, float and double data types. |
| |
| [[header-opencl_math_constants-synopsis]] |
| ==== Header <opencl_math_constants> Synopsis |
| |
| [source] |
| ---- |
| namespace cl |
| { |
| template<class T> class math_constants; |
| |
| #ifdef cl_khr_fp16 |
| #define M_E_H see below |
| #define M_LOG2E_H see below |
| #define M_LOG10E_H see below |
| #define M_LN2_H see below |
| #define M_LN10_H see below |
| #define M_PI_H see below |
| #define M_PI_2_H see below |
| #define M_PI_4_H see below |
| #define M_1_PI_H see below |
| #define M_2_PI_H see below |
| #define M_2_SQRTPI_H see below |
| #define M_SQRT2_H see below |
| #define M_SQRT1_2_H see below |
| |
| template<> class math_constants<half>; |
| template<> class math_constants<half2>; |
| template<> class math_constants<half3>; |
| template<> class math_constants<half4>; |
| template<> class math_constants<half8>; |
| template<> class math_constants<half16>; |
| #endif |
| |
| #define M_E_F see below |
| #define M_LOG2E_F see below |
| #define M_LOG10E_F see below |
| #define M_LN2_F see below |
| #define M_LN10_F see below |
| #define M_PI_F see below |
| #define M_PI_2_F see below |
| #define M_PI_4_F see below |
| #define M_1_PI_F see below |
| #define M_2_PI_F see below |
| #define M_2_SQRTPI_F see below |
| #define M_SQRT2_F see below |
| #define M_SQRT1_2_F see below |
| |
| template<> class math_constants<float>; |
| template<> class math_constants<float2>; |
| template<> class math_constants<float3>; |
| template<> class math_constants<float4>; |
| template<> class math_constants<float8>; |
| template<> class math_constants<float16>; |
| |
| #ifdef cl_khr_fp64 |
| #define M_E see below |
| #define M_LOG2E see below |
| #define M_LOG10E see below |
| #define M_LN2 see below |
| #define M_LN10 see below |
| #define M_PI see below |
| #define M_PI_2 see below |
| #define M_PI_4 see below |
| #define M_1_PI see below |
| #define M_2_PI see below |
| #define M_2_SQRTPI see below |
| #define M_SQRT2 see below |
| #define M_SQRT1_2 see below |
| |
| template<> class math_constants<double>; |
| template<> class math_constants<double2>; |
| template<> class math_constants<double3>; |
| template<> class math_constants<double4>; |
| template<> class math_constants<double8>; |
| template<> class math_constants<double16>; |
| #endif |
| |
| template<class T> |
| constexpr T e_v = math_constants<T>::e(); |
| template<class T> |
| constexpr T log2e_v = math_constants<T>::log2e(); |
| template<class T> |
| constexpr T log10e_v = math_constants<T>::log10e(); |
| template<class T> |
| constexpr T ln2_v = math_constants<T>::ln2(); |
| template<class T> |
| constexpr T ln10_v = math_constants<T>::ln10(); |
| template<class T> |
| constexpr T pi_v = math_constants<T>::pi(); |
| template<class T> |
| constexpr T pi_2_v = math_constants<T>::pi_2(); |
| template<class T> |
| constexpr T pi_4_v = math_constants<T>::pi_4(); |
| template<class T> |
| constexpr T one_pi_v = math_constants<T>::one_pi(); |
| template<class T> |
| constexpr T two_pi_v = math_constants<T>::two_pi(); |
| template<class T> |
| constexpr T two_sqrtpi_v = math_constants<T>::two_sqrtpi(); |
| template<class T> |
| constexpr T sqrt2_v = math_constants<T>::sqrt2(); |
| template<class T> |
| constexpr T sqrt1_2_v = math_constants<T>::sqrt1_2(); |
| |
| } |
| ---- |
| |
| [[class-math_constants]] |
| ==== Class math_constants |
| |
| [source] |
| ---- |
| namespace cl |
| { |
| template<class T> |
| class math_constants |
| { |
| public: |
| static constexpr T e() noexcept { return T(); } |
| static constexpr T log2e() noexcept { return T(); } |
| static constexpr T log10e() noexcept { return T(); } |
| static constexpr T ln2() noexcept { return T(); } |
| static constexpr T ln10() noexcept { return T(); } |
| static constexpr T pi() noexcept { return T(); } |
| static constexpr T pi_2() noexcept { return T(); } |
| static constexpr T pi_4() noexcept { return T(); } |
| static constexpr T one_pi() noexcept { return T(); } |
| static constexpr T two_pi() noexcept { return T(); } |
| static constexpr T two_sqrtpi() noexcept { return T(); } |
| static constexpr T sqrt2() noexcept { return T(); } |
| static constexpr T sqrt1_2() noexcept { return T(); } |
| }; |
| |
| } |
| ---- |
| |
| [[half-constants]] |
| ==== Half Constants |
| |
| The following constants are also available. |
| They are of type `half` and are accurate within the precision of the `half` type. |
| |
| .Half Constants |
| [width="100%",cols="50%,50%",options="header"] |
| |==== |
| | *Constant* |
| | *Description* |
| |
| | `e` |
| | Value of e |
| |
| | `log2e` |
| | Value of log~2~e |
| |
| | `log10e` |
| | Value of log~10~e |
| |
| | `ln2` |
| | Value of log~e~2 |
| |
| | `ln10` |
| | Value of log~e~10 |
| |
| | `pi` |
| | Value of {pi} |
| |
| | `pi_2` |
| | Value of {pi} / 2 |
| |
| | `pi_4` |
| | Value of {pi} / 4 |
| |
| | `one_pi` |
| | Value of 1 / {pi} |
| |
| | `two_pi` |
| | Value of 2 / {pi} |
| |
| | `two_sqrtpi` |
| | Value of 2 / {sqrt}{pi} |
| |
| | `sqrt2` |
| | Value of {sqrt}2 |
| |
| | `sqrt1_2` |
| | Value of 1 / {sqrt}2 |
| |==== |
| |
| [[float-constants]] |
| ==== Float Constants |
| |
| The following constants are also available. |
| They are of type `float` and are accurate within the precision of the `float` type. |
| |
| .Float Constants |
| [width="100%",cols="50%,50%",options="header"] |
| |==== |
| | *Constant* |
| | *Description* |
| |
| | `e` |
| | Value of e |
| |
| | `log2e` |
| | Value of log~2~e |
| |
| | `log10e` |
| | Value of log~10~e |
| |
| | `ln2` |
| | Value of log~e~2 |
| |
| | `ln10` |
| | Value of log~e~10 |
| |
| | `pi` |
| | Value of {pi} |
| |
| | `pi_2` |
| | Value of {pi} / 2 |
| |
| | `pi_4` |
| | Value of {pi} / 4 |
| |
| | `one_pi` |
| | Value of 1 / {pi} |
| |
| | `two_pi` |
| | Value of 2 / {pi} |
| |
| | `two_sqrtpi` |
| | Value of 2 / {sqrt}{pi} |
| |
| | `sqrt2` |
| | Value of {sqrt}2 |
| |
| | `sqrt1_2` |
| | Value of 1 / {sqrt}2 |
| |==== |
| |
| [[double-constants]] |
| ==== Double Constants |
| |
| The following constants are also available. |
| They are of type `double` and are accurate within the precision of the `double` type. |
| |
| .Double Constants |
| [width="100%",cols="50%,50%",options="header"] |
| |==== |
| | *Constant* |
| | *Description* |
| |
| | `e` |
| | Value of e |
| |
| | `log2e` |
| | Value of log~2~e |
| |
| | `log10e` |
| | Value of log~10~e |
| |
| | `ln2` |
| | Value of log~e~2 |
| |
| | `ln10` |
| | Value of log~e~10 |
| |
| | `pi` |
| | Value of {pi} |
| |
| | `pi_2` |
| | Value of {pi} / 2 |
| |
| | `pi_4` |
| | Value of {pi} / 4 |
| |
| | `one_pi` |
| | Value of 1 / {pi} |
| |
| | `two_pi` |
| | Value of 2 / {pi} |
| |
| | `two_sqrtpi` |
| | Value of 2 / {sqrt}{pi} |
| |
| | `sqrt2` |
| | Value of {sqrt}2 |
| |
| | `sqrt1_2` |
| | Value of 1 / {sqrt}2 |
| |==== |