From 4dca3090deb8092a29e06f806fa754b8b9e9c2c4 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Thu, 18 Jan 2024 17:36:44 -0600 Subject: [PATCH] Avoid `convert` in `^` --- src/intervals/arithmetic/power.jl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/intervals/arithmetic/power.jl b/src/intervals/arithmetic/power.jl index 739d548a7..09a607dfd 100644 --- a/src/intervals/arithmetic/power.jl +++ b/src/intervals/arithmetic/power.jl @@ -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 @@ -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)) @@ -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))