JuliaMath / JuliaMath/Decimals.jl
negative powers don't work
Open
- 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.