From 6e09fc2ee5f99e0761d6cf232c00b549e5fa18d8 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 17 Mar 2014 17:06:41 +0900 Subject: [PATCH] add math::phi --- sprout/math.hpp | 1 + sprout/math/constant_variables.hpp | 239 +++++++++++++++-------------- sprout/math/constants.hpp | 7 + 3 files changed, 130 insertions(+), 117 deletions(-) diff --git a/sprout/math.hpp b/sprout/math.hpp index 6bcab616..b25e1f3d 100644 --- a/sprout/math.hpp +++ b/sprout/math.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_MATH_HPP diff --git a/sprout/math/constant_variables.hpp b/sprout/math/constant_variables.hpp index a3aae35d..028e2e0c 100644 --- a/sprout/math/constant_variables.hpp +++ b/sprout/math/constant_variables.hpp @@ -1,117 +1,122 @@ -/*============================================================================= - Copyright (c) 2014 fimbul - https://github.com/fimbul - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#ifndef SPROUT_MATH_CONSTANT_VARIABLES_HPP -#define SPROUT_MATH_CONSTANT_VARIABLES_HPP - -#include -#if SPROUT_USE_VARIABLE_TEMPLATES -# include -#endif // #if SPROUT_USE_VARIABLE_TEMPLATES - -namespace sprout { -#if SPROUT_USE_VARIABLE_TEMPLATES - namespace math { - // - // pi - // - template - SPROUT_STATIC_CONSTEXPR T pi_v = sprout::math::pi(); - // - // half_pi - // - template - SPROUT_STATIC_CONSTEXPR T half_pi_v = sprout::math::half_pi(); - // - // third_pi - // two_thirds_pi - // - template - SPROUT_STATIC_CONSTEXPR T third_pi_v = sprout::math::third_pi(); - template - SPROUT_STATIC_CONSTEXPR T two_thirds_pi_v = sprout::math::two_thirds_pi(); - // - // quarter_pi - // three_quarters_pi - // - template - SPROUT_STATIC_CONSTEXPR T quarter_pi_v = sprout::math::quarter_pi(); - template - SPROUT_STATIC_CONSTEXPR T three_quarters_pi_v = sprout::math::three_quarters_pi(); - // - // two_pi - // four_pi - // - template - SPROUT_STATIC_CONSTEXPR T two_pi_v = sprout::math::two_pi(); - template - SPROUT_STATIC_CONSTEXPR T four_pi_v = sprout::math::four_pi(); - // - // two_div_pi - // root_two_div_pi - // - template - SPROUT_STATIC_CONSTEXPR T two_div_pi_v = sprout::math::two_div_pi(); - template - SPROUT_STATIC_CONSTEXPR T root_two_div_pi_v = sprout::math::root_two_div_pi(); - // - // root_pi - // one_div_root_pi - // root_one_div_pi - // two_div_root_pi - // - template - SPROUT_STATIC_CONSTEXPR T root_pi_v = sprout::math::root_pi(); - template - SPROUT_STATIC_CONSTEXPR T one_div_root_pi_v = sprout::math::one_div_root_pi(); - template - SPROUT_STATIC_CONSTEXPR T root_one_div_pi_v = sprout::math::root_one_div_pi(); - template - SPROUT_STATIC_CONSTEXPR T two_div_root_pi_v = sprout::math::two_div_root_pi(); - // - // half - // quarter - // third - // two_thirds - // - template - SPROUT_STATIC_CONSTEXPR T half_v = sprout::math::half(); - template - SPROUT_STATIC_CONSTEXPR T quarter_v = sprout::math::quarter(); - template - SPROUT_STATIC_CONSTEXPR T third_v = sprout::math::third(); - template - SPROUT_STATIC_CONSTEXPR T two_thirds_v = sprout::math::two_thirds(); - // - // root_two - // root_three - // half_root_two - // - template - SPROUT_STATIC_CONSTEXPR T root_two_v = sprout::math::root_two(); - template - SPROUT_STATIC_CONSTEXPR T root_three_v = sprout::math::root_three(); - template - SPROUT_STATIC_CONSTEXPR T half_root_two_v = sprout::math::half_root_two(); - // - // e - // - template - SPROUT_STATIC_CONSTEXPR T e_v = sprout::math::e(); - // - // ln_ten - // ln_two - // - template - SPROUT_STATIC_CONSTEXPR T ln_ten_v = sprout::math::ln_ten(); - template - SPROUT_STATIC_CONSTEXPR T ln_two_v = sprout::math::ln_two(); - } // namespace math -#endif // #if SPROUT_USE_VARIABLE_TEMPLATES -} // namespace sprout - -#endif // #ifndef SPROUT_MATH_CONSTANT_VARIABLES_HPP +/*============================================================================= + Copyright (c) 2014 fimbul + https://github.com/fimbul + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_MATH_CONSTANT_VARIABLES_HPP +#define SPROUT_MATH_CONSTANT_VARIABLES_HPP + +#include +#if SPROUT_USE_VARIABLE_TEMPLATES +# include +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + +namespace sprout { + namespace math { +#if SPROUT_USE_VARIABLE_TEMPLATES + // + // pi + // + template + SPROUT_STATIC_CONSTEXPR T pi_v = sprout::math::pi(); + // + // half_pi + // + template + SPROUT_STATIC_CONSTEXPR T half_pi_v = sprout::math::half_pi(); + // + // third_pi + // two_thirds_pi + // + template + SPROUT_STATIC_CONSTEXPR T third_pi_v = sprout::math::third_pi(); + template + SPROUT_STATIC_CONSTEXPR T two_thirds_pi_v = sprout::math::two_thirds_pi(); + // + // quarter_pi + // three_quarters_pi + // + template + SPROUT_STATIC_CONSTEXPR T quarter_pi_v = sprout::math::quarter_pi(); + template + SPROUT_STATIC_CONSTEXPR T three_quarters_pi_v = sprout::math::three_quarters_pi(); + // + // two_pi + // four_pi + // + template + SPROUT_STATIC_CONSTEXPR T two_pi_v = sprout::math::two_pi(); + template + SPROUT_STATIC_CONSTEXPR T four_pi_v = sprout::math::four_pi(); + // + // two_div_pi + // root_two_div_pi + // + template + SPROUT_STATIC_CONSTEXPR T two_div_pi_v = sprout::math::two_div_pi(); + template + SPROUT_STATIC_CONSTEXPR T root_two_div_pi_v = sprout::math::root_two_div_pi(); + // + // root_pi + // one_div_root_pi + // root_one_div_pi + // two_div_root_pi + // + template + SPROUT_STATIC_CONSTEXPR T root_pi_v = sprout::math::root_pi(); + template + SPROUT_STATIC_CONSTEXPR T one_div_root_pi_v = sprout::math::one_div_root_pi(); + template + SPROUT_STATIC_CONSTEXPR T root_one_div_pi_v = sprout::math::root_one_div_pi(); + template + SPROUT_STATIC_CONSTEXPR T two_div_root_pi_v = sprout::math::two_div_root_pi(); + // + // half + // quarter + // third + // two_thirds + // + template + SPROUT_STATIC_CONSTEXPR T half_v = sprout::math::half(); + template + SPROUT_STATIC_CONSTEXPR T quarter_v = sprout::math::quarter(); + template + SPROUT_STATIC_CONSTEXPR T third_v = sprout::math::third(); + template + SPROUT_STATIC_CONSTEXPR T two_thirds_v = sprout::math::two_thirds(); + // + // root_two + // root_three + // half_root_two + // + template + SPROUT_STATIC_CONSTEXPR T root_two_v = sprout::math::root_two(); + template + SPROUT_STATIC_CONSTEXPR T root_three_v = sprout::math::root_three(); + template + SPROUT_STATIC_CONSTEXPR T half_root_two_v = sprout::math::half_root_two(); + // + // e + // + template + SPROUT_STATIC_CONSTEXPR T e_v = sprout::math::e(); + // + // ln_ten + // ln_two + // + template + SPROUT_STATIC_CONSTEXPR T ln_ten_v = sprout::math::ln_ten(); + template + SPROUT_STATIC_CONSTEXPR T ln_two_v = sprout::math::ln_two(); + // + // phi + // + template + SPROUT_STATIC_CONSTEXPR T phi_v = sprout::math::phi(); +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + } // namespace math +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_CONSTANT_VARIABLES_HPP diff --git a/sprout/math/constants.hpp b/sprout/math/constants.hpp index 278320ad..f625a435 100644 --- a/sprout/math/constants.hpp +++ b/sprout/math/constants.hpp @@ -154,6 +154,13 @@ namespace sprout { inline SPROUT_CONSTEXPR T ln_two() { return static_cast(0.693147180559945309417232121458176568075500134360255254120680009493393621969694715605863326996418687542001481021L); } + // + // phi + // + template + inline SPROUT_CONSTEXPR T phi() { + return static_cast(1.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408807L); + } } // namespace math } // namespace sprout