X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;ds=sidebyside;f=ginac%2Fnumeric.cpp;h=1d4de9f5b416d4e997f6d590f0c96ef7edb57e4c;hb=e98841136efa88c951edafc0cd43ba1343f20b5b;hp=37a1ba3f02283fada1e439f97c89ae9c471ca3b4;hpb=47837c4973890ce46756f0865f2347f76bd2b015;p=ginac.git diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index 37a1ba3f..1d4de9f5 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -758,8 +758,9 @@ const numeric numeric::div(const numeric &other) const * returns result as a numeric object. */ const numeric numeric::power(const numeric &other) const { - // Efficiency shortcut: trap the neutral exponent by pointer. - if (&other==_num1_p) + // Shortcut for efficiency and numeric stability (as in 1.0 exponent): + // trap the neutral exponent. + if (&other==_num1_p || cln::equal(cln::the(other.value),cln::the(_num1.value))) return *this; if (cln::zerop(cln::the(value))) { @@ -782,7 +783,8 @@ const numeric numeric::power(const numeric &other) const * an ex object, where the result would end up on the heap anyways. */ const numeric &numeric::add_dyn(const numeric &other) const { - // Efficiency shortcut: trap the neutral element by pointer. + // Efficiency shortcut: trap the neutral element by pointer. This hack + // is supposed to keep the number of distinct numeric objects low. if (this==_num0_p) return other; else if (&other==_num0_p) @@ -842,8 +844,10 @@ const numeric &numeric::div_dyn(const numeric &other) const * heap anyways. */ const numeric &numeric::power_dyn(const numeric &other) const { - // Efficiency shortcut: trap the neutral exponent by pointer. - if (&other==_num1_p) + // Efficiency shortcut: trap the neutral exponent (first try by pointer, then + // try harder, since calls to cln::expt() below may return amazing results for + // floating point exponent 1.0). + if (&other==_num1_p || cln::equal(cln::the(other.value),cln::the(_num1.value))) return *this; if (cln::zerop(cln::the(value))) {