cppx-core
named-numbers.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 
18 #include <cppx-core/language/types/Truth.hpp> // cppx::Truth
19 
20 #include <c/math.hpp>
21 #include <limits> // std::numeric_limits
22 
23 namespace cppx
24 {
25  CPPX_USE_STD( numeric_limits );
26 
27 #ifdef M_PI
28  const auto e = M_E; // e 2.71828182845904523536
29  const auto log2e = M_LOG2E; // log2(e) 1.44269504088896340736
30  const auto log10e = M_LOG10E; // log10(e) 0.434294481903251827651
31  const auto ln2 = M_LN2; // ln(2) 0.693147180559945309417
32  const auto ln10 = M_LN10; // ln(10) 2.30258509299404568402
33  const auto pi = M_PI; // pi 3.14159265358979323846
34  // pi/2 M_PI_2 1.57079632679489661923
35  // pi/4 M_PI_4 0.785398163397448309616
36  // 1/pi M_1_PI 0.318309886183790671538
37  // 2/pi M_2_PI 0.636619772367581343076
38  const auto inv_sqrt_pi = M_2_SQRTPI/2; // 2/sqrt(pi) 1.12837916709551257390
39  const auto sqrt2 = M_SQRT2; // sqrt(2) 1.41421356237309504880
40  const auto inv_sqrt2 = M_SQRT1_2; // 1/sqrt(2) 0.707106781186547524401
41 #else
42  const auto e = 2.71828182845904523536;
43  const auto log2e = 1.44269504088896340736;
44  const auto log10e = 0.434294481903251827651;
45  const auto ln2 = 0.693147180559945309417;
46  const auto ln10 = 2.30258509299404568402;
47  const auto pi = 3.14159265358979323846;
48  //1.57079632679489661923
49  //0.785398163397448309616
50  //0.318309886183790671538
51  //0.636619772367581343076
52  const auto inv_sqrt_pi = 1.12837916709551257390;
53  const auto sqrt2 = 1.41421356237309504880;
54  const auto inv_sqrt2 = 0.707106781186547524401;
55 #endif
56  template< class Number = double >
57  constexpr Truth has_nan_ = numeric_limits<Number>::has_quiet_NaN;
58 
59  constexpr Truth has_nan = has_nan_<double>;
60 
61  template< class Number >
62  constexpr auto nan_()
63  -> Number
64  { return numeric_limits<Number>::quiet_NaN(); }
65 
66  constexpr inline auto nan()
67  -> double
68  { return nan_<double>(); }
69 
70  template< class Number = double >
72 
73  constexpr Truth has_infinity = has_infinity_<double>;
74 
75  template< class Number >
76  constexpr auto infinity_()
77  -> Number
79 
80  constexpr inline auto infinity()
81  -> double
82  { return infinity_<double>(); }
83 
84  namespace calc
85  {
89  );
90  } // namespace calc
91 
92 } // namespace cppx
constexpr Truth has_nan_
constexpr auto nan_() -> Number
const auto e
const auto ln10
A drop-in replacement for bool without implicit conversion from/to types other than bool.
Definition: Truth.hpp:34
const auto log2e
constexpr Truth has_infinity_
constexpr Truth has_infinity
constexpr auto nan() -> double
const auto ln2
CPPX_USE_CPPX(intpow, squared, cubed)
Truth is a drop-in replacement for bool without implicit conversion from/to types other than bool.
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
const auto inv_sqrt2
constexpr auto infinity() -> double
constexpr auto infinity_() -> Number
constexpr Truth has_nan
const auto inv_sqrt_pi
const auto log10e
const auto pi
Macros for generating more concise and clear using statements, primarily $use_cppx and $use_std,...
const auto sqrt2