This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients mark.dickinson, martin.panter, ned.deily, rhettinger, serhiy.storchaka, steven.daprano, tim.peters, vstinner
Date 2016-08-28.04:01:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Adding one more version of the last code, faster by cutting the number of extra digits used, and by playing "the usual" low-level CPython speed tricks.

I don't claim it's always correctly rounded - although I haven't found a specific case where it isn't.  I do claim it will return the exact result whenever the exact result is representable as a float.

I also claim it's "fast enough" - this version does on the high end of 50 to 100 thousand roots per second on my box, pretty much independent of `n`.

    import decimal
    c = decimal.DefaultContext.copy()
    c.prec = 25
    def rootn(x, n,
        g = D(x**(1.0/n))
        n1 = D(n-1)
        g = div(add(mul(n1, g),
                    div(D(x), pow(g, n1))),
        return float(g)
    del decimal, c
Date User Action Args
2016-08-28 04:01:34tim.peterssetrecipients: + tim.peters, rhettinger, mark.dickinson, vstinner, ned.deily, steven.daprano, martin.panter, serhiy.storchaka
2016-08-28 04:01:34tim.peterssetmessageid: <>
2016-08-28 04:01:34tim.peterslinkissue27761 messages
2016-08-28 04:01:32tim.peterscreate