[issue20499] Rounding errors with statistics.variance
Wolfgang Maier
report at bugs.python.org
Sat Feb 8 23:59:51 CET 2014
Wolfgang Maier added the comment:
I worked out a slightly speedier version of decimal_to_ratio today (Stefan: that's when I duplicated your bug report):
from decimal import Context
def _decimal_to_ratio (x):
_, digits, exp = x.as_tuple()
if exp in _ExactRatio.decimal_infinite: # INF, NAN, sNAN
assert not d.is_finite()
raise ValueError
if exp < 0:
exp = -exp
return int(x.scaleb(exp, Context(prec=len(digits)))), 10**exp
return int(x), 1
makes the variance functions in my re-implementation about 20-30% faster for Decimal. It's not a big breakthrough, but still.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20499>
_______________________________________
More information about the Python-bugs-list
mailing list