Skip to content

Commit

Permalink
Avoid convert in ^
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenet committed Jan 18, 2024
1 parent 946493a commit 4dca309
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/intervals/arithmetic/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ function Base.:^(x::Interval, y::Interval)
return _unsafe_interval(bareinterval(r), d, t)
end

Base.:^(n::Integer, y::Interval) = ^(n//one(n), y)
Base.:^(x::Interval, n::Integer) = ^(x, n//one(n))
Base.:^(x::Rational, y::Interval) = ^(convert(Interval{typeof(x)}, x), y)
Base.:^(x::Interval, y::Rational) = ^(x, convert(Interval{typeof(y)}, y))
Base.:^(n::Integer, y::Interval) = _select_pow(power_mode(), n, y)
Base.:^(x::Interval, n::Integer) = _select_pow(power_mode(), x, n)
Base.:^(x::Rational, y::Interval) = _select_pow(power_mode(), x, y)
Base.:^(x::Interval, y::Rational) = _select_pow(power_mode(), x, y)
Base.:^(x::AbstractFloat, y::Interval) = _select_pow(power_mode(), x, y)
Base.:^(x::Interval, y::AbstractFloat) = _select_pow(power_mode(), x, y)

# overwrite behaviour for small integer powers from https://github.com/JuliaLang/julia/pull/24240
Base.literal_pow(::typeof(^), x::Interval, ::Val{n}) where {n} = x^n
Expand Down Expand Up @@ -130,8 +132,6 @@ function pow(x::BareInterval{T}, y::BareInterval{S}) where {T<:NumTypes,S<:Ratio
return BareInterval{R}(hull(_pow(x, inf(y)), _pow(x, sup(y))))
end

pow(n::Integer, y::BareInterval) = pow(n//one(n), y)
pow(x::BareInterval, n::Integer) = pow(x, n//one(n))
pow(x::Real, y::BareInterval) = pow(bareinterval(x), y)
pow(x::BareInterval, y::Real) = pow(x, bareinterval(y))

Expand All @@ -145,8 +145,6 @@ function pow(x::Interval, y::Interval)
return _unsafe_interval(r, d, t)
end

pow(n::Integer, y::Interval) = pow(n//one(n), y)
pow(x::Interval, n::Integer) = pow(x, n//one(n))
pow(x::Real, y::Interval) = pow(interval(x), y)
pow(x::Interval, y::Real) = pow(x, interval(y))

Expand Down

0 comments on commit 4dca309

Please sign in to comment.