💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.9 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_MATH_NUMBERS_HPP
  20. #define ANTKEEPER_MATH_NUMBERS_HPP
  21. #include <limits>
  22. #include <numbers>
  23. namespace math {
  24. /// Mathematical constants.
  25. namespace numbers {
  26. /// Positive infinity.
  27. template <class T>
  28. inline constexpr T inf = std::numeric_limits<T>::infinity();
  29. /// e.
  30. template <class T>
  31. inline constexpr T e = std::numbers::e_v<T>;
  32. /// log2(e).
  33. template <class T>
  34. inline constexpr T log2_e = std::numbers::log2e_v<T>;
  35. /// log10(e).
  36. template <class T>
  37. inline constexpr T log10_e = std::numbers::log10e_v<T>;
  38. /// Pi.
  39. template <class T>
  40. inline constexpr T pi = std::numbers::pi_v<T>;
  41. /// Pi * 2.
  42. template <class T>
  43. inline constexpr T two_pi = pi<T> * T{2};
  44. /// Pi * 4.
  45. template <class T>
  46. inline constexpr T four_pi = pi<T> * T{4};
  47. /// Pi / 2.
  48. template <class T>
  49. inline constexpr T half_pi = pi<T> / T{2};
  50. /// 1 / Pi.
  51. template <class T>
  52. inline constexpr T inv_pi = std::numbers::inv_pi_v<T>;
  53. /// 1 / sqrt(Pi).
  54. template <class T>
  55. inline constexpr T inv_sqrt_pi = std::numbers::inv_sqrtpi_v<T>;
  56. /// ln(2).
  57. template <class T>
  58. inline constexpr T ln_2 = std::numbers::ln2_v<T>;
  59. /// ln(10).
  60. template <class T>
  61. inline constexpr T ln_10 = std::numbers::ln10_v<T>;
  62. /// sqrt(0.5)
  63. template <class T>
  64. inline constexpr T sqrt_half = T{0.70710678118654752440084436210485};
  65. /// sqrt(2)
  66. template <class T>
  67. inline constexpr T sqrt_2 = std::numbers::sqrt2_v<T>;
  68. /// sqrt(3)
  69. template <class T>
  70. inline constexpr T sqrt_3 = std::numbers::sqrt3_v<T>;
  71. /// 1 / sqrt(3)
  72. template <class T>
  73. inline constexpr T inv_sqrt_3 = std::numbers::inv_sqrt3_v<T>;
  74. /// sqrt(5)
  75. template <class T>
  76. inline constexpr T sqrt_5 = T{2.2360679774997896964091736687313};
  77. /// Euler–Mascheroni constant.
  78. template <class T>
  79. inline constexpr T egamma = std::numbers::egamma_v<T>;
  80. /// Golden ratio constant.
  81. template <class T>
  82. inline constexpr T phi = std::numbers::phi_v<T>;
  83. /// Degrees-to-radians conversion factor.
  84. template <class T>
  85. inline constexpr T deg2rad = pi<T> / T{180};
  86. /// Radians-to-degrees conversion factor.
  87. template <class T>
  88. inline constexpr T rad2deg = T{180} / pi<T>;
  89. } // namespace numbers
  90. // Bring math::numbers into math namespace
  91. using namespace numbers;
  92. } // namespace math
  93. #endif // ANTKEEPER_MATH_NUMBERS_HPP