Message374928
Here's code to illustrate the idea. It doesn't yet handle zeros, infinities or nans; that support would need to be added.
import math
def fprod(numbers):
# Product of numbers, avoiding intermediate underflow and overflow.
# Does not handle zeros, infinities or nans
# Running product is acc_m * 2**acc_e
acc_m, acc_e = float.fromhex("1p1000"), -1000
count = 0
for number in numbers:
m, e = math.frexp(number)
acc_m *= m
acc_e += e
if count == 1000:
if acc_m < 1.0:
acc_m = math.ldexp(acc_m, 1000)
acc_e -= 1000
count = 0
return math.ldexp(acc_m, acc_e) |
|
Date |
User |
Action |
Args |
2020-08-06 11:24:43 | mark.dickinson | set | recipients:
+ mark.dickinson, tim.peters, rhettinger, veky, pablogsal, Jeffrey.Kintscher |
2020-08-06 11:24:43 | mark.dickinson | set | messageid: <1596713083.06.0.785395116095.issue41458@roundup.psfhosted.org> |
2020-08-06 11:24:43 | mark.dickinson | link | issue41458 messages |
2020-08-06 11:24:42 | mark.dickinson | create | |
|