Logo
Explore Help
Register Sign In
fengqi/lv_micropython
1
0
Fork 0
You've already forked lv_micropython
Code Issues Pull Requests 1 Actions Packages Projects Releases Wiki Activity
lv_micropython/tests/float/math_factorial_intbig.py

15 lines
287 B
Python
Raw Normal View History

py/modmath: Add math.factorial, optimised and non-opt implementations. 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.
2018-08-27 10:32:21 +10:00
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')
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.8 Page: 26ms Template: 1ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API