inline typename Functor::result_type sum_series(Functor& func, int bits, boost::uintmax_t& max_terms, const U& init_value) { BOOST_MATH_STD_USING typedef typename Functor::result_type result_type; result_type factor = ldexp(result_type(1), 1 - bits); return sum_series(func, factor, max_terms, init_value); }
inline typename Functor::result_type sum_series(Functor& func, int bits, boost::uintmax_t& max_terms) { BOOST_MATH_STD_USING typedef typename Functor::result_type result_type; result_type init_val = 0; return sum_series(func, bits, max_terms, init_val); }
inline typename Functor::result_type sum_series(Functor& func, int bits) { BOOST_MATH_STD_USING typedef typename Functor::result_type result_type; boost::uintmax_t iters = (std::numeric_limits<boost::uintmax_t>::max)(); result_type init_val = 0; return sum_series(func, bits, iters, init_val); }
int main() { double d; d = sum_series(4, 0.5, 0.25, 0.125, 0.0625); printf("Sum of series is %f.\n", d); return 0; }
int sum_series(int a, int b) { int x; if (a > b) return -1; if ( (a < b) && (a != b)) return (a + sum_series(a + 1, b)); if (a == b) return b; }
main() { int a, b, sum; printf("Enter two digits\n"); scanf("%d%d", &a, &b); printf("\na = %d b = %d\n", a, b); sum = sum_series(a,b); if (sum == -1) printf("Unable to process, since a > b\n"); else printf("Sum of series, from %d to %d = %d\n", a, b, sum); }
inline typename Functor::result_type sum_series(Functor& func, int bits, const U& init_value) { BOOST_MATH_STD_USING boost::uintmax_t iters = (std::numeric_limits<boost::uintmax_t>::max)(); return sum_series(func, bits, iters, init_value); }
inline typename Functor::result_type sum_series(Functor& func, const U& factor, boost::uintmax_t& max_terms) { typename Functor::result_type init_value = 0; return sum_series(func, factor, max_terms, init_value); }