8c656754aa
This commit adds the math.factorial function in two variants: - squared difference, which is faster than the naive version, relatively compact, and non-recursive; - a mildly optimised recursive version, faster than the above one. There are some more optimisations that could be done, but they tend to take more code, and more storage space. The recursive version seems like a sensible compromise. The new function is disabled by default, and uses the non-optimised version by default if it is enabled. The options are MICROPY_PY_MATH_FACTORIAL and MICROPY_OPT_MATH_FACTORIAL.
15 lines
287 B
Python
15 lines
287 B
Python
try:
|
|
import math
|
|
math.factorial
|
|
except (ImportError, AttributeError):
|
|
print('SKIP')
|
|
raise SystemExit
|
|
|
|
|
|
for fun in (math.factorial,):
|
|
for x in range(-1, 30):
|
|
try:
|
|
print('%d' % fun(x))
|
|
except ValueError as e:
|
|
print('ValueError')
|