]> www.ginac.de Git - ginac.git/blobdiff - ginac/numeric.cpp
* Fix signed/unsigned bug in bernoulli function.
[ginac.git] / ginac / numeric.cpp
index 9670c6b36e716eaebca1477ef53ef8f635580403..8825bdb992f6a78825fef3b9ace567a3b0e64591 100644 (file)
@@ -1708,7 +1708,7 @@ const numeric bernoulli(const numeric &nn)
        results.reserve(n/2);
        for (unsigned p=next_r; p<=n;  p+=2) {
                cln::cl_I  c = 1;  // seed for binonmial coefficients
-               cln::cl_RA b = cln::cl_RA(1-p)/2;
+               cln::cl_RA b = cln::cl_RA(p-1)/-2;
                const unsigned p3 = p+3;
                const unsigned pm = p-2;
                unsigned i, k, p_2;
@@ -1999,14 +1999,25 @@ _numeric_digits::_numeric_digits()
                throw(std::runtime_error("I told you not to do instantiate me!"));
        too_late = true;
        cln::default_float_format = cln::float_format(17);
+
+       // add callbacks for built-in functions
+       // like ... add_callback(Li_lookuptable);
 }
 
 
 /** Assign a native long to global Digits object. */
 _numeric_digits& _numeric_digits::operator=(long prec)
 {
+       long digitsdiff = prec - digits;
        digits = prec;
-       cln::default_float_format = cln::float_format(prec); 
+       cln::default_float_format = cln::float_format(prec);
+
+       // call registered callbacks
+       std::vector<digits_changed_callback>::const_iterator it = callbacklist.begin(), end = callbacklist.end();
+       for (; it != end; ++it) {
+               (*it)(digitsdiff);
+       }
+
        return *this;
 }
 
@@ -2026,6 +2037,13 @@ void _numeric_digits::print(std::ostream &os) const
 }
 
 
+/** Add a new callback function. */
+void _numeric_digits::add_callback(digits_changed_callback callback)
+{
+       callbacklist.push_back(callback);
+}
+
+
 std::ostream& operator<<(std::ostream &os, const _numeric_digits &e)
 {
        e.print(os);