Skip to content

Commit bdd66ef

Browse files
Merge pull request #207 from araujoms/main
fix power with negative integers
2 parents 6340f1d + af5180f commit bdd66ef

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
Manifest.toml
12
*.jl.cov
23
*.jl.*.cov
34
*.jl.mem
45
deps/deps.jl
5-
.DS_Store
6+
.DS_Store

src/math/elementary/explog.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ function Base.:(^)(r::DoubleFloat{T}, n::DoubleFloat{T}) where {T <: IEEEFloat}
123123
if isinteger(n)
124124
return r^Int64(Float64(n)) # convert n to Float64 first
125125
else
126-
return exp(n * log(r))
126+
return exp(n * log(r))
127127
end
128128
end
129129

130130
function Base.:(^)(r::Int, n::DoubleFloat{T}) where {T<:IEEEFloat}
131131
if isinteger(n)
132-
return r^Int64(Float64(n)) # convert n to Float64 first
132+
return DoubleFloat{T}(r)^Int64(Float64(n)) # convert n to Float64 first
133133
else
134134
return exp(n * log(r))
135135
end

test/functions.jl

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ end
1717
@test Double64(10.0)^0 == Double64(1.0)
1818
@test Double64(10.0)^1 == Double64(10.0)
1919
@test Double64(0.0)^0 == Double64(1.0)
20+
@test 2^Double64(-3) == 0.125
21+
@test isa(2^Double16(1), Double16)
22+
@test isa(2^Double16(-1), Double16)
23+
@test isa(2^Double32(1), Double32)
24+
@test isa(2^Double32(-1), Double32)
25+
@test isa(2^Double64(1), Double64)
26+
@test isa(2^Double64(-1), Double64)
2027
end
2128

2229
f64a = sqrt(2.0)

0 commit comments

Comments
 (0)