Skip to content

negative powers don't work #117

Description

@stevengj

This error seems incorrect:

julia> (dec"0.1234")^-2
ERROR: DomainError with -2:
Cannot raise an integer x to a negative power -2.

Maybe define:

Base.:^(x::Decimal, p::Integer) = p >= 0 ? Base.power_by_squaring(x, p) : Base.power_by_squaring(inv(x), -p)

or alternatively use exp(p * log(abs(x))) * (isnegative(x) ? (-1)^isodd(p) : 1), not sure which is faster.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions