Skip to content

mathtools

Source

Tools for math.

safediv

safediv(a, b) avoids the division by zero exception, by returning infinite with proper sign.

Info

Closely referring IEEE Standard 754.

safediv(0, 0)
# nan

safediv(1, 0)
# inf

safediv(-1, 0)
# -inf

safediv(1, 1)
# 1.0

product

product(*nums) computes the product of all the numbers in nums.

product(*(0.1 * n for n in range(1, 101)))
# 9.332621544394479e+57