3 // Preprocessed pi constant, annotated.
13 template <class T> struct constant_pi
16 // Default implementations from string of decimal digits:
17 static inline T get_from_string()
20 = detail::convert_from_string<T>("3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651e+00",
21 boost::is_convertible<const char*, T>());
24 template <int N> static T compute();
27 // Default implementations from string of decimal digits:
28 static inline T get(const mpl::int_<construct_from_string>&)
30 constant_initializer<T, & constant_pi<T>::get_from_string >::do_nothing();
31 return get_from_string();
33 // Float, double and long double versions:
34 static inline T get(const mpl::int_<construct_from_float>)
36 return 3.141592653589793238462643383279502884e+00F;
38 static inline T get(const mpl::int_<construct_from_double>&)
40 return 3.141592653589793238462643383279502884e+00;
42 static inline T get(const mpl::int_<construct_from_long_double>&)
44 return 3.141592653589793238462643383279502884e+00L;
46 // For very high precision that is nonetheless can be calculated at compile time:
47 template <int N> static inline T get(const mpl::int_<N>& n)
49 constant_initializer2<T, N, & constant_pi<T>::template compute<N> >::do_nothing();
52 //For true arbitrary precision, which may well vary at runtime.
53 static inline T get(const mpl::int_<0>&)
55 return tools::digits<T>() > max_string_digits ? compute<0>() : get(mpl::int_<construct_from_string>());
57 }; // template <class T> struct constant_pi
60 // The actual forwarding function (including policy to control precision).
61 template <class T, class Policy> inline T pi( )
63 return detail:: constant_pi<T>::get(typename construction_traits<T, Policy>::type());
65 // The actual forwarding function (using default policy to control precision).
66 template <class T> inline T pi()
68 return pi<T, boost::math::policies::policy<> >()
70 } // namespace constants
72 // Namespace specific versions, for the three built-in floats:
73 namespace float_constants
75 static const float pi = 3.141592653589793238462643383279502884e+00F;
77 namespace double_constants
79 static const double pi = 3.141592653589793238462643383279502884e+00;
81 namespace long_double_constants
83 static const long double pi = 3.141592653589793238462643383279502884e+00L;
86 } // namespace constants
90 //] [/preprocessed_pi]
93 Copyright 2012 John Maddock and Paul A. Bristow.
94 Distributed under the Boost Software License, Version 1.0.
95 (See accompanying file LICENSE_1_0.txt or copy at
96 http://www.boost.org/LICENSE_1_0.txt)