JuliaMath / JuliaMath/Decimals.jl

negative powers don't work

Open
#117 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
62
Forks
24
PR merge metrics
No merged PRs in 30d

Description

This error seems incorrect:
```jl
julia> (dec"0.1234")^-2
ERROR: DomainError with -2:
Cannot raise an integer x to a negative power -2.
```
Maybe define:
```jl
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.