[issue27761] Private _nth_root function loses accuracy

Tim Peters report at bugs.python.org
Sun Aug 28 11:42:34 EDT 2016


Tim Peters added the comment:

Victor, happy to add comments, but only if there's sufficient interest in actually using this.  In the context of this issue report, it's really only important that Mark understands it, and he already does ;-)

For example, it starts with float `**` because that's by far the fastest way to get a very good approximation.  Then it switches to Decimal to perform a Newton step using greater-than-float precision, which is necessary to absorb rounding errors in intermediate steps.  Then it rounds back to float, because it has to - it's a "float in, float out" function.  It's for the same reason, e.g., that Mark's `nroot` converts floats to potentially gigantic integers for its Newton step(s), and my other `fractions.Fraction` function converts floats to potentially gigantic rationals.  "Potentially gigantic" may be necessary to guarantee always-correct rounding of the final result, but isn't necessary to guarantee < 1 ulp error in the final result.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27761>
_______________________________________


More information about the Python-bugs-list mailing list