|
Boost : |
From: Paul A. Bristow (boost_at_[hidden])
Date: 2004-01-20 15:13:22
This method of providing constants was rejected by a formal review,
and a _portable_ method meeting all requirements is still being worked on by
Daniel Frey. (Any progress Daniel?)
Paul
Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]
| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Andy Little
| Sent: Tuesday, January 20, 2004 3:30 PM
| To: boost_at_[hidden]
| Subject: [boost] math_constants parameterisation and return by ref
|
|
| Hi,
|
| Have been looking through math-constants in order to take advantage of
| the PI functions in function_constants.hpp.
|
| Two thoughts have occurred.
|
| 1) the type of constant could be parameterised, which would help in
| functions-templates:
|
| current usege of 'pi' in function_constants:
|
| q_volume::m3 V1 = 4.0/3.0 * boost::math::double_constants::pi *
| power<3>(r);
|
| Alternative parameterised pi ...useful for template functions:
|
| q_volume::m3 V2 = 4.0/3.0 * boost::math::constants<double>::pi *
| power<3>(r);
| q_volume::m3 V3 = 4.0/3.0 * boost::math::constants<float>::pi *
| power<3>(r);
|
| 2) the value could be returned by const-reference.
|
| An implementation which does both of these and shouldnt break the original:
| (tested in gcc3.2 and VC7.1):
|
| regards
| Andy Little
|
| ---------------------------
|
| #ifndef HPP_FUNCTION_CONSTANTS_BY_REF
| #define HPP_FUNCTION_CONSTANTS_BY_REF
|
| namespace boost{namespace math {
|
| template<typename T>
| struct constants{
| struct pi_constant
| {
| operator const T& ()const;
| };
| static pi_constant const pi;
|
| /* other constants */
| };
|
| // conv operators
| template<>
| inline constants<
| double
| >::pi_constant::operator
| const double&() const
| { static const double val
| = 3.141592653589793238462643383279502884197;
| return val;
| }
|
| template<>
| inline constants<
| float
| >::pi_constant::operator
| const float&() const
| { static const float val
| = 3.141592653589793238462643383279502884197F;
| return val;
| }
|
| // static members
| // initialisers reqd which is possibly the problem ? :-)
|
| template<>
| constants<double>::pi_constant const
| constants<double>::pi = constants<double>::pi_constant();
|
| template<>
| constants<float>::pi_constant const
| constants<float>::pi = constants<float>::pi_constant();
|
| }}// boost::math
|
| #endif
|
|
|
|
|
|
|
|
|
|
| _______________________________________________
| Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
|
|
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk