Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66760 - in sandbox/math_constants: . boost boost/math boost/math/constants libs libs/math libs/math/test
From: john_at_[hidden]
Date: 2010-11-25 13:56:54


Author: johnmaddock
Date: 2010-11-25 13:56:54 EST (Thu, 25 Nov 2010)
New Revision: 66760
URL: http://svn.boost.org/trac/boost/changeset/66760

Log:
Initial commit of improved math-constant support.
Added:
   sandbox/math_constants/
   sandbox/math_constants/boost/
   sandbox/math_constants/boost/math/
   sandbox/math_constants/boost/math/constants/
   sandbox/math_constants/boost/math/constants/constants.hpp
      - copied, changed from r66753, /trunk/boost/math/constants/constants.hpp
   sandbox/math_constants/libs/
   sandbox/math_constants/libs/math/
   sandbox/math_constants/libs/math/test/
   sandbox/math_constants/libs/math/test/test_constants.cpp
      - copied unchanged from r66753, /trunk/libs/math/test/test_constants.cpp
Text files modified:
   sandbox/math_constants/boost/math/constants/constants.hpp | 103 ++++++++++++++++++++++++++++-----------
   1 files changed, 73 insertions(+), 30 deletions(-)

Copied: sandbox/math_constants/boost/math/constants/constants.hpp (from r66753, /trunk/boost/math/constants/constants.hpp)
==============================================================================
--- /trunk/boost/math/constants/constants.hpp (original)
+++ sandbox/math_constants/boost/math/constants/constants.hpp 2010-11-25 13:56:54 EST (Thu, 25 Nov 2010)
@@ -16,6 +16,7 @@
 #ifdef BOOST_MSVC
 #pragma warning(pop)
 #endif
+#include <boost/mpl/int.hpp>
 
 namespace boost{ namespace math
 {
@@ -35,42 +36,84 @@
     // (This is necessary because you can't use a numeric constant
     // since even a long double might not have enough digits).
 
-
- #define BOOST_DEFINE_MATH_CONSTANT(name, x, y, exp)\
- template <class T> inline T name(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))\
+ enum construction_method
+ {
+ construct_from_float = 0,
+ construct_from_double = 1,
+ construct_from_long_double = 2,
+ construct_from_string = 3,
+ construct_from_calculation = 4,
+ };
+
+ template <class Real>
+ struct construction_traits
+ {
+ BOOST_STATIC_CONSTANT(construction_method, value = construct_from_string);
+ };
+ template <>
+ struct construction_traits<float>
+ {
+ BOOST_STATIC_CONSTANT(construction_method, value = construct_from_float);
+ };
+ template <>
+ struct construction_traits<double>
+ {
+ BOOST_STATIC_CONSTANT(construction_method, value = construct_from_double);
+ };
+ template <>
+ struct construction_traits<long double>
+ {
+ BOOST_STATIC_CONSTANT(construction_method, value = construct_from_long_double);
+ };
+
+ #define BOOST_DEFINE_MATH_CONSTANT(name, x, y, exp)\
+ /* Forward declaration of the calculation method, just in case it's not been provided yet */ \
+ template <class T> T BOOST_JOIN(calculate_, name)(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)); \
+ /* The default implementations come next: */ \
+ template <class T> inline T BOOST_JOIN(get_, name)(const mpl::int_<construct_from_string>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))\
    {\
       static const T result = ::boost::lexical_cast<T>(BOOST_STRINGIZE(BOOST_JOIN(BOOST_JOIN(x, y), BOOST_JOIN(e, exp))));\
       return result;\
    }\
- template <> inline float name<float>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float))\
+ template <class T> inline T BOOST_JOIN(get_, name)(const mpl::int_<construct_from_float>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))\
    { return BOOST_JOIN(BOOST_JOIN(x, BOOST_JOIN(e, exp)), F); }\
- template <> inline double name<double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(double))\
+ template <class T> inline T BOOST_JOIN(get_, name)(const mpl::int_<construct_from_double>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))\
    { return BOOST_JOIN(x, BOOST_JOIN(e, exp)); }\
- template <> inline long double name<long double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(long double))\
- { return BOOST_JOIN(BOOST_JOIN(x, BOOST_JOIN(e, exp)), L); }
-
- BOOST_DEFINE_MATH_CONSTANT(pi, 3.141592653589793238462643383279502884197169399375105820974944, 59230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196, 0)
- BOOST_DEFINE_MATH_CONSTANT(two_pi, 6.2831853071795864769252867665590057683943388015061, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(one_div_two_pi, 0.70710678118654752440084436210484903928483593756084, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(root_pi, 1.7724538509055160272981674833411451827975, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(root_half_pi, 1.253314137315500251207882642405522626503, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(root_two_pi, 2.506628274631000502415765284811045253007, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(root_ln_four, 1.1774100225154746910115693264596996377473856893858205385225257565000, 2658854698492680841813836877081, 0)
- BOOST_DEFINE_MATH_CONSTANT(e, 2.7182818284590452353602874713526624977572470936999595749669676, 27724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763233829880753195251019011, 0)
- BOOST_DEFINE_MATH_CONSTANT(half, 0.5, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(euler, 0.577215664901532860606512090082402431042159335939923598805, 76723488486, 0)
- BOOST_DEFINE_MATH_CONSTANT(root_two, 1.414213562373095048801688724209698078569671875376948073, 17667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206, 0)
- BOOST_DEFINE_MATH_CONSTANT(half_root_two, 0.70710678118654752440084436210484903928483593756084, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(ln_two, 0.693147180559945309417232121458176568075500134360255254, 120680009493393621969694715605863326996418687, 0)
- BOOST_DEFINE_MATH_CONSTANT(ln_ln_two, -0.36651292058166432701243915823266946945426344783710526305367771367056, 16153193527385494558228566989083583025230453648347655663425171940646634, 0)
- BOOST_DEFINE_MATH_CONSTANT(third, 0.3333333333333333333333333333333333333333333333333333333333333333333333, 3333333333333333333333333333333333333333333333333333333333333333333333333, 0)
- BOOST_DEFINE_MATH_CONSTANT(twothirds, 0.66666666666666666666666666666666666666666666666666666666666666666666, 66666666666666666666666666666666666666666666666666666666666666666666667, 0)
- BOOST_DEFINE_MATH_CONSTANT(pi_minus_three, 0.141592653589793238462643383279502884197169399375105820974944, 59230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196, 0)
- BOOST_DEFINE_MATH_CONSTANT(four_minus_pi, 0.85840734641020676153735661672049711580283060062489417902505540769218359, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(pow23_four_minus_pi, 0.79531676737159754434839533505680658072763917332771320544530223438582161, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(exp_minus_half, 0.6065306597126334236037995349911804534419181354871869556828921587350565194137, 484239986476115079894560, 0)
- BOOST_DEFINE_MATH_CONSTANT(one_div_root_two, 0.70710678118654752440084436210484903928483593756084, 0, 0)
- BOOST_DEFINE_MATH_CONSTANT(one_div_root_two_pi, 0.39894228040143267793994605993438186847585863095671, 0, 0)
+ template <class T> inline T BOOST_JOIN(get_, name)(const mpl::int_<construct_from_long_double>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))\
+ { return BOOST_JOIN(BOOST_JOIN(x, BOOST_JOIN(e, exp)), L); }\
+ template <class T> inline T BOOST_JOIN(get_, name)(const mpl::int_<construct_from_calculation>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))\
+ { static const T result = BOOST_JOIN(calculate_, name)<T>(); return result; }\
+ /* The actual forwarding function: */ \
+ template <class T> inline T name(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T))\
+ { return BOOST_JOIN(get_, name)<T>(mpl::int_<construction_traits<T>::value>()); }\
+ /* Now the namespace specific versions: */ \
+ } namespace float_constants{ static const float name = BOOST_JOIN(BOOST_JOIN(x, BOOST_JOIN(e, exp)), F); }\
+ namespace double_constants{ static const double name = BOOST_JOIN(x, BOOST_JOIN(e, exp)); } \
+ namespace long_double_constants{ static const long double name = BOOST_JOIN(BOOST_JOIN(x, BOOST_JOIN(e, exp)), L); }\
+ namespace constants{
+
+ BOOST_DEFINE_MATH_CONSTANT(pi, 3.141592653589793238462643383279502884197169399375105820974944, 59230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196, 0)
+ BOOST_DEFINE_MATH_CONSTANT(two_pi, 6.2831853071795864769252867665590057683943388015061, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(one_div_two_pi, 0.70710678118654752440084436210484903928483593756084, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(root_pi, 1.7724538509055160272981674833411451827975, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(root_half_pi, 1.253314137315500251207882642405522626503, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(root_two_pi, 2.506628274631000502415765284811045253007, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(root_ln_four, 1.1774100225154746910115693264596996377473856893858205385225257565000, 2658854698492680841813836877081, 0)
+ BOOST_DEFINE_MATH_CONSTANT(e, 2.7182818284590452353602874713526624977572470936999595749669676, 27724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763233829880753195251019011, 0)
+ BOOST_DEFINE_MATH_CONSTANT(half, 0.5, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(euler, 0.577215664901532860606512090082402431042159335939923598805, 76723488486, 0)
+ BOOST_DEFINE_MATH_CONSTANT(root_two, 1.414213562373095048801688724209698078569671875376948073, 17667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206, 0)
+ BOOST_DEFINE_MATH_CONSTANT(half_root_two, 0.70710678118654752440084436210484903928483593756084, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(ln_two, 0.693147180559945309417232121458176568075500134360255254, 120680009493393621969694715605863326996418687, 0)
+ BOOST_DEFINE_MATH_CONSTANT(ln_ln_two, -0.36651292058166432701243915823266946945426344783710526305367771367056, 16153193527385494558228566989083583025230453648347655663425171940646634, 0)
+ BOOST_DEFINE_MATH_CONSTANT(third, 0.3333333333333333333333333333333333333333333333333333333333333333333333, 3333333333333333333333333333333333333333333333333333333333333333333333333, 0)
+ BOOST_DEFINE_MATH_CONSTANT(twothirds, 0.66666666666666666666666666666666666666666666666666666666666666666666, 66666666666666666666666666666666666666666666666666666666666666666666667, 0)
+ BOOST_DEFINE_MATH_CONSTANT(pi_minus_three, 0.141592653589793238462643383279502884197169399375105820974944, 59230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196, 0)
+ BOOST_DEFINE_MATH_CONSTANT(four_minus_pi, 0.85840734641020676153735661672049711580283060062489417902505540769218359, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(pow23_four_minus_pi, 0.79531676737159754434839533505680658072763917332771320544530223438582161, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(exp_minus_half, 0.6065306597126334236037995349911804534419181354871869556828921587350565194137, 484239986476115079894560, 0)
+ BOOST_DEFINE_MATH_CONSTANT(one_div_root_two, 0.70710678118654752440084436210484903928483593756084, 0, 0)
+ BOOST_DEFINE_MATH_CONSTANT(one_div_root_two_pi, 0.39894228040143267793994605993438186847585863095671, 0, 0)
 
 
   } // namespace constants


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk