Boost logo

Boost-Commit :

From: bruno.lalande_at_[hidden]
Date: 2008-05-26 06:00:03


Author: bruno.lalande
Date: 2008-05-26 06:00:02 EDT (Mon, 26 May 2008)
New Revision: 45768
URL: http://svn.boost.org/trac/boost/changeset/45768

Log:
Reduced again the number of template instanciations
Text files modified:
   sandbox/math_toolkit/boost/math/special_functions/pow.hpp | 55 +++++++++++++++++----------------------
   1 files changed, 24 insertions(+), 31 deletions(-)

Modified: sandbox/math_toolkit/boost/math/special_functions/pow.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/special_functions/pow.hpp (original)
+++ sandbox/math_toolkit/boost/math/special_functions/pow.hpp 2008-05-26 06:00:02 EDT (Mon, 26 May 2008)
@@ -26,60 +26,53 @@
 namespace detail {
 
 
-template <int N, bool odd>
-struct positive_power;
-
-template <>
-struct positive_power<0, false>
+template <int N, int M = N%2>
+struct positive_power
 {
     template <typename T>
- static typename tools::promote_args<T>::type result(T)
- { return 1; }
+ static typename tools::promote_args<T>::type result(T base)
+ {
+ typename tools::promote_args<T>::type power =
+ positive_power<N/2>::result(base);
+ return power * power;
+ }
 };
 
-template <>
-struct positive_power<1, false>
+template <int N>
+struct positive_power<N, 1>
 {
     template <typename T>
- static typename tools::promote_args<T>::type result(T x)
- { return x; }
+ static typename tools::promote_args<T>::type result(T base)
+ {
+ typename tools::promote_args<T>::type power =
+ positive_power<N/2>::result(base);
+ return base * power * power;
+ }
 };
 
 template <>
-struct positive_power<2, false>
+struct positive_power<0, 0>
 {
     template <typename T>
- static typename tools::promote_args<T>::type result(T base)
- { return base*base; }
+ static typename tools::promote_args<T>::type result(T)
+ { return T(1); }
 };
 
-template <int N, bool odd>
-struct positive_power
+template <>
+struct positive_power<1, 1>
 {
     template <typename T>
     static typename tools::promote_args<T>::type result(T base)
- {
- return base*positive_power<N-1, (N-1)%2>::result(base);
- }
+ { return base; }
 };
 
-template <int N>
-struct positive_power<N, false>
-{
- template <typename T>
- static typename tools::promote_args<T>::type result(T base)
- {
- return positive_power<2, false>::result(
- positive_power<N/2, (N/2)%2>::result(base));
- }
-};
 
 template <int N, bool>
 struct power_if_positive
 {
     template <typename T, class Policy>
     static typename tools::promote_args<T>::type result(T base, const Policy&)
- { return positive_power<N, N%2>::result(base); }
+ { return positive_power<N>::result(base); }
 };
 
 template <int N>
@@ -98,7 +91,7 @@
                    );
         }
 
- return T(1) / positive_power<-N, (-N)%2>::result(base);
+ return T(1) / positive_power<-N>::result(base);
     }
 };
 


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