Skip to content

Math support: pow() --use log for efficiency increase #123

@saxbophone

Description

@saxbophone

Current code for pow() uses divide-and-conquer recursion to avoid a degenerate-case linear recursion, which is very very very slow for large exponents.

However, we still manually repeatedly divide the exponent by $2$ to work out how many powers of $2$ this is, roughly. We then use this information to use the laws of powers to combine smaller powers into increasingly larger powers.

This repeated division is equivalent to calculating the base-2 logarithm, $log{2}(b)$. We should consider using our ilog() function to do this instead.

Whenever our exponent is not an exact power of $2$, there will be an additional bit that needs to be dealt with to get the full result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions