Skip to content
Snippets Groups Projects
  • Christopher Swenson's avatar
    8c656754
    py/modmath: Add math.factorial, optimised and non-opt implementations. · 8c656754
    Christopher Swenson authored
    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.
    8c656754
    History
    py/modmath: Add math.factorial, optimised and non-opt implementations.
    Christopher Swenson authored
    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.