All Classes Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Mathematical Constants

Defines mathematical constants commonly in use. More...

Functions

template<typename T >
constexpr T gears::math::pi () noexcept
 Computes pi with the precision needed.
 
template<typename T >
constexpr T gears::math::half () noexcept
 Computes one half with the precision needed.
 
template<typename T >
constexpr T gears::math::third () noexcept
 Computes one third with the precision needed.
 
template<typename T >
constexpr T gears::math::root_two () noexcept
 Computes √2 with the precision needed.
 
template<typename T >
constexpr T gears::math::ln_two () noexcept
 Computes pi with the precision needed.
 
template<typename T >
constexpr T gears::math::half_pi () noexcept
 Computes half pi with the precision needed.
 
template<typename T >
constexpr T gears::math::third_pi () noexcept
 Computes one third pi with the precision needed.
 
template<typename T >
constexpr T gears::math::two_thirds_pi () noexcept
 Computes two thirds pi with the precision needed.
 
template<typename T >
constexpr T gears::math::sixth_pi () noexcept
 Computes one sixth pi with the precision needed.
 
template<typename T >
constexpr T gears::math::three_fourths_pi () noexcept
 Computes three fourths pi with the precision needed.
 
template<typename T >
constexpr T gears::math::four_thirds_pi () noexcept
 Computes four thirds pi with the precision needed.
 
template<typename T >
constexpr T gears::math::two_pi () noexcept
 Computes two pi with the precision needed.
 

Detailed Description

These functions compute their respective named constants up to the precision of the type given. The maximum valid precision that is guaranteed to be valid is std::numeric_limits<T>::digits10 + 2. This is to allow proper roundtrip calculations. For integer types the computed constant is floored. So pi<int>() would return 3. All constants provided are constexpr.

Example usage:

#include <gears/math/constants.hpp>
using namespace gears;
template<typename T>
constexpr T area(T radius) {
return math::pi<T>() * radius * radius;
}
int main() {
static_assert(area<double>(4) == 50.26548245743669, "...");
}