From cb289f8416f0bca370cc6a818380a7b52c41a92b Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Fri, 2 Jun 2000 23:26:39 +0000 Subject: [PATCH] - bernoulli(numeric): speedup. --- ginac/numeric.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index c3ba81d6..f755c335 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -1468,7 +1468,7 @@ const numeric binomial(const numeric & n, const numeric & k) } } - // should really be gamma(n+1)/(gamma(r+1)/gamma(n-r+1) or a suitable limit + // should really be gamma(n+1)/gamma(r+1)/gamma(n-r+1) or a suitable limit throw (std::range_error("numeric::binomial(): donĀ“t know how to evaluate that.")); } @@ -1492,29 +1492,29 @@ const numeric bernoulli(const numeric & nn) // codes it (preferably in CLN) we make this a remembering function which // computes its results using the defining formula // B(nn) == - 1/(nn+1) * sum_{k=0}^{nn-1}(binomial(nn+1,k)*B(k)) - // whith B(0) == 1. + // with B(0) == 1. // Be warned, though: the Bernoulli numbers are computationally very // expensive anyhow and you shouldn't expect miracles to happen. - static vector results; + static vector results; static int highest_result = -1; int n = nn.sub(_num2()).div(_num2()).to_int(); if (n <= highest_result) - return results[n]; + return numeric(results[n]); if (results.capacity() < (unsigned)(n+1)) results.reserve(n+1); - numeric tmp; // used to store the sum + cl_RA tmp; // used to store the sum for (int i=highest_result+1; i<=n; ++i) { // the first two elements: - tmp = numeric(-2*i-1,2); + tmp = cl_I(-2*i-1)/cl_I(2); // accumulate the remaining elements: for (int j=0; j