Skip to content

vsexprtools: add missing atan2 #67

Description

@Ichunjo

PoC

class ExprOp(ExprOpBase, CustomEnum):
    # Not Implemented in akarin or std
    PI = f"{pi}", 0
    SGN = "dup 0 > x 0 < -", 1
    NEG = "-1 *", 1
    TAN = "dup sin swap cos /", 1

   ...

    @classmethod
    def atan(cls, c: str = "x", n: int = 5) -> ExprList:
        # Approximation using Taylor series
        n = max(2, n)

        expr = ExprList([c, "dup", "var!"])

        for i in range(1, n):
            expr.append("var@", 2 * i + 1, ExprOp.POW, 2 * i + 1, ExprOp.DIV, ExprOp.SUB if i % 2 else ExprOp.ADD)

        return expr

    @classmethod
    def asin(cls, c: str = "x", n: int = 5) -> ExprList:
        return cls.atan(
            str(ExprList([c, ExprOp.DUP, ExprOp.DUP, ExprOp.MUL, 1, ExprOp.SWAP, ExprOp.SUB, ExprOp.SQRT, ExprOp.DIV])), n
        )

    @classmethod
    def acos(cls, c: str = "x", n: int = 5) -> ExprList:
        return ExprList([cls.PI, 2, ExprOp.DIV, cls.asin(c, n), ExprOp.SUB])

Taylor series should be good enough for |x| < 1 but it'll probably be necessary to use domain reduction for |x| > 1.
Suggestions welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions