~ubuntu-branches/ubuntu/saucy/deal.ii/saucy

« back to all changes in this revision

Viewing changes to contrib/boost/include/boost/math/tools/series.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV, Adam C. Powell, IV, Denis Barbier
  • Date: 2010-07-29 13:47:01 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100729134701-akb8jb3stwge8tcm
Tags: 6.3.1-1
[ Adam C. Powell, IV ]
* Changed to source format 3.0 (quilt).
* Changed maintainer to debian-science with Adam Powell as uploader.
* Added source lintian overrides about Adam Powell's name.
* Added Vcs info on git repository.
* Bumped Standards-Version.
* Changed stamp-patch to patch target and fixed its application criterion.
* Moved make_dependencies and expand_instantiations to a versioned directory
  to avoid shlib package conflicts.

[ Denis Barbier ]
* New upstream release (closes: #562332).
  + Added libtbb support.
  + Forward-ported all patches.
* Updates for new PETSc version, including workaround for different versions
  of petsc and slepc.
* Add debian/watch.
* Update to debhelper 7.
* Added pdebuild patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
#include <boost/config/no_tr1/cmath.hpp>
14
14
#include <boost/cstdint.hpp>
 
15
#include <boost/limits.hpp>
15
16
#include <boost/math/tools/config.hpp>
16
17
 
17
18
namespace boost{ namespace math{ namespace tools{
19
20
//
20
21
// Simple series summation come first:
21
22
//
22
 
template <class Functor>
23
 
typename Functor::result_type sum_series(Functor& func, int bits)
24
 
{
25
 
   BOOST_MATH_STD_USING
26
 
 
27
 
   typedef typename Functor::result_type result_type;
28
 
 
29
 
   result_type factor = pow(result_type(2), bits);
30
 
   result_type result = func();
31
 
   result_type next_term;
32
 
   do{
33
 
      next_term = func();
34
 
      result += next_term;
35
 
   }
36
 
   while(fabs(result) < fabs(factor * next_term));
37
 
   return result;
38
 
}
39
 
 
40
 
template <class Functor>
41
 
typename Functor::result_type sum_series(Functor& func, int bits, boost::uintmax_t& max_terms)
42
 
{
43
 
   BOOST_MATH_STD_USING
44
 
 
45
 
   typedef typename Functor::result_type result_type;
46
 
 
47
 
   boost::uintmax_t counter = max_terms;
48
 
 
49
 
   result_type factor = ldexp(result_type(1), bits);
50
 
   result_type result = func();
51
 
   result_type next_term;
52
 
   do{
53
 
      next_term = func();
54
 
      result += next_term;
55
 
   }
56
 
   while((fabs(result) < fabs(factor * next_term)) && --counter);
57
 
 
58
 
   // set max_terms to the actual number of terms of the series evaluated:
59
 
   max_terms = max_terms - counter;
60
 
 
61
 
   return result;
62
 
}
63
 
 
64
 
template <class Functor, class U>
65
 
typename Functor::result_type sum_series(Functor& func, int bits, U init_value)
66
 
{
67
 
   BOOST_MATH_STD_USING
68
 
 
69
 
   typedef typename Functor::result_type result_type;
70
 
 
71
 
   result_type factor = ldexp(result_type(1), bits);
72
 
   result_type result = static_cast<result_type>(init_value);
73
 
   result_type next_term;
74
 
   do{
75
 
      next_term = func();
76
 
      result += next_term;
77
 
   }
78
 
   while(fabs(result) < fabs(factor * next_term));
79
 
 
80
 
   return result;
81
 
}
82
 
 
83
 
template <class Functor, class U>
84
 
typename Functor::result_type sum_series(Functor& func, int bits, boost::uintmax_t& max_terms, U init_value)
85
 
{
86
 
   BOOST_MATH_STD_USING
87
 
 
88
 
   typedef typename Functor::result_type result_type;
89
 
 
90
 
   boost::uintmax_t counter = max_terms;
91
 
 
92
 
   result_type factor = ldexp(result_type(1), bits);
 
23
template <class Functor, class U, class V>
 
24
inline typename Functor::result_type sum_series(Functor& func, const U& factor, boost::uintmax_t& max_terms, const V& init_value)
 
25
{
 
26
   BOOST_MATH_STD_USING
 
27
 
 
28
   typedef typename Functor::result_type result_type;
 
29
 
 
30
   boost::uintmax_t counter = max_terms;
 
31
 
93
32
   result_type result = init_value;
94
33
   result_type next_term;
95
34
   do{
96
35
      next_term = func();
97
36
      result += next_term;
98
37
   }
99
 
   while((fabs(result) < fabs(factor * next_term)) && --counter);
 
38
   while((fabs(factor * result) < fabs(next_term)) && --counter);
100
39
 
101
40
   // set max_terms to the actual number of terms of the series evaluated:
102
41
   max_terms = max_terms - counter;
104
43
   return result;
105
44
}
106
45
 
 
46
template <class Functor, class U>
 
47
inline typename Functor::result_type sum_series(Functor& func, const U& factor, boost::uintmax_t& max_terms)
 
48
{
 
49
   typename Functor::result_type init_value = 0;
 
50
   return sum_series(func, factor, max_terms, init_value);
 
51
}
 
52
 
 
53
template <class Functor, class U>
 
54
inline typename Functor::result_type sum_series(Functor& func, int bits, boost::uintmax_t& max_terms, const U& init_value)
 
55
{
 
56
   BOOST_MATH_STD_USING
 
57
   typedef typename Functor::result_type result_type;
 
58
   result_type factor = ldexp(result_type(1), 1 - bits);
 
59
   return sum_series(func, factor, max_terms, init_value);
 
60
}
 
61
 
 
62
template <class Functor>
 
63
inline typename Functor::result_type sum_series(Functor& func, int bits)
 
64
{
 
65
   BOOST_MATH_STD_USING
 
66
   typedef typename Functor::result_type result_type;
 
67
   boost::uintmax_t iters = (std::numeric_limits<boost::uintmax_t>::max)();
 
68
   result_type init_val = 0;
 
69
   return sum_series(func, bits, iters, init_val);
 
70
}
 
71
 
 
72
template <class Functor>
 
73
inline typename Functor::result_type sum_series(Functor& func, int bits, boost::uintmax_t& max_terms)
 
74
{
 
75
   BOOST_MATH_STD_USING
 
76
   typedef typename Functor::result_type result_type;
 
77
   result_type init_val = 0;
 
78
   return sum_series(func, bits, max_terms, init_val);
 
79
}
 
80
 
 
81
template <class Functor, class U>
 
82
inline typename Functor::result_type sum_series(Functor& func, int bits, const U& init_value)
 
83
{
 
84
   BOOST_MATH_STD_USING
 
85
   boost::uintmax_t iters = (std::numeric_limits<boost::uintmax_t>::max)();
 
86
   return sum_series(func, bits, iters, init_value);
 
87
}
 
88
 
107
89
//
108
90
// Algorithm kahan_sum_series invokes Functor func until the N'th
109
91
// term is too small to have any effect on the total, the terms
117
99
// in any case the result is still much better than a naive summation.
118
100
//
119
101
template <class Functor>
120
 
typename Functor::result_type kahan_sum_series(Functor& func, int bits)
 
102
inline typename Functor::result_type kahan_sum_series(Functor& func, int bits)
121
103
{
122
104
   BOOST_MATH_STD_USING
123
105
 
140
122
}
141
123
 
142
124
template <class Functor>
143
 
typename Functor::result_type kahan_sum_series(Functor& func, int bits, boost::uintmax_t& max_terms)
 
125
inline typename Functor::result_type kahan_sum_series(Functor& func, int bits, boost::uintmax_t& max_terms)
144
126
{
145
127
   BOOST_MATH_STD_USING
146
128