➜

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.

作者 tim.peters
收信人 mark.dickinson, rhettinger, serhiy.storchaka, tim.peters
日期 2020-08-15.17:44:58
SpamBayes Score -1.0
Marked as misclassified 是
Message-id <1597513498.54.0.93133822141.issue41513@roundup.psfhosted.org>
In-reply-to
内容
> ...
> one at a time subtract a**2 (an argument squared) in descending
> order of magnitude
> ...

But that doesn't really help unless the sum of squares was computed without care to begin with. Can do as well by skipping that but instead computing the original sum of squares in increasing order of magnitude.

Cheapest way I know of that "seemingly always" reproduces the Decimal result (when that's rounded back to float) combines fsum(), Veltkamp splitting, and the correction trick from the paper:

    def split(x, T27=ldexp(1.0, 27)+1.0):
        t = x * T27
        hi = t - (t - x)
        lo = x - hi
        assert hi + lo == x
        return hi, lo

    # result := hypot(*xs)
    parts = []
    for x in xs:
        a, b = split(x)
        parts.append(a*a)
        parts.append(2.0*a*b)
        parts.append(b*b)
    result = sqrt(fsum(parts))
    a, b = split(result)
    parts.append(-a*a)
    parts.append(-2.0*a*b)
    parts.append(-b*b)
    x = fsum(parts) # best float approx to sum(x_i ** 2) - result**2
    result += x / (2.0 * result)
历史
日期 用户 动作 参数
2020-08-15 17:44:58tim.peters修改recipients: + tim.peters, rhettinger, mark.dickinson, serhiy.storchaka
2020-08-15 17:44:58tim.peters修改messageid: <1597513498.54.0.93133822141.issue41513@roundup.psfhosted.org>
2020-08-15 17:44:58tim.peters链接issue41513 messages
2020-08-15 17:44:58tim.peters创建