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, rhettinger, serhiy.storchaka, skrah, steven.daprano, tim.peters
Date 2018-03-19.19:12:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Mark, thanks!  I'm happy with that resolution:  if any argument is infinite, return +inf; else if any argument is a NaN, return a NaN; else do something useful ;-)

Serhiy, yes, the scaling that prevents catastrophic overflow/underflow due to naively squaring unscaled values can introduce small errors of its own.  A single-rounding dot product could avoid that, leaving two sources of single-rounding errors (the dot product, and the square root).

Raymond, yes, fsum() on its own can reduce errors.  Note that scaling on its own can also reduce errors (in particular, when the arguments are all the same, they're each scaled to exactly 1.0):

>>> import math
>>> n = 1000
>>> math.sqrt(sum([0.1 ** 2] * n))
>>> math.sqrt(math.fsum([0.1 ** 2] * n))
>>> hypot(*([0.1] * n)) # using the code above
>>> math.sqrt(n) * 0.1
Date User Action Args
2018-03-19 19:12:07tim.peterssetrecipients: + tim.peters, rhettinger, mark.dickinson, steven.daprano, skrah, serhiy.storchaka
2018-03-19 19:12:06tim.peterssetmessageid: <>
2018-03-19 19:12:06tim.peterslinkissue33089 messages
2018-03-19 19:12:06tim.peterscreate