Skip to content

Slight optimization for log2(x). #1016

Description

@haydenwong7bm

Currently, the implementation of log2(x) is to compute ln(x)/ln(2). Since mpmath numbers is represented by mag ⋅ 2exp, it is usually computed as (exp ⋅ ln(2) + ln(mag)) / ln(2), with some special cases that are computed as (exp ⋅ ln(2)) / ln(2), which causes an overhead in multiplying and diving the constant ln(2). It can be simply computed as exp + ln(mag) / ln(2), saving 1 multiplication, possibly can be implemented by a keyword argument on mpf_ln().
It can be generalized to complex z: log2(z) = log2(|z|) + i(arg(z) / ln(2))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions