Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHnt committed Jan 15, 2024
1 parent c267e44 commit b4eef85
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 20 deletions.
59 changes: 50 additions & 9 deletions src/intervals/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ for (f, fname) ∈ ((:+, :add), (:-, :sub), (:*, :mul), (:/, :div))

$g(::IntervalRounding, x::T, y::T, r::RoundingMode) where {T<:AbstractFloat} =
$g(IntervalRounding{:slow}(), x, y, r)

# $g(::IntervalRounding{:fast}, x::T, y::T, ::RoundingMode{:Down}) where {T<:AbstractFloat} =
# prevfloat($f(x, y))
# $g(::IntervalRounding{:fast}, x::T, y::T, ::RoundingMode{:Up}) where {T<:AbstractFloat} =
# nextfloat($f(x, y))

$g(::IntervalRounding{:tight}, x::T, y::T, ::RoundingMode{:Down}) where {T<:Union{Float32,Float64}} =
RoundingEmulator.$(Symbol(fname, :_down))(x, y)
$g(::IntervalRounding{:tight}, x::T, y::T, ::RoundingMode{:Up}) where {T<:Union{Float32,Float64}} =
RoundingEmulator.$(Symbol(fname, :_up))(x, y)

function $g(::IntervalRounding{:slow}, x::T, y::T, r::RoundingMode) where {T<:AbstractFloat}
prec = max(precision(x), precision(y))
bigx = BigFloat(x; precision = prec)
Expand All @@ -46,6 +49,7 @@ for (f, fname) ∈ ((:+, :add), (:-, :sub), (:*, :mul), (:/, :div))
)::Int32
return bigz
end

$g(::IntervalRounding{:none}, x::T, y::T, ::RoundingMode) where {T<:AbstractFloat} = $f(x, y)
end
end
Expand All @@ -59,10 +63,12 @@ _pow_round(x::Rational, n::Integer, ::RoundingMode) = ^(x, n) # exact operation

_pow_round(::IntervalRounding, x::T, y::T, r::RoundingMode) where {T<:AbstractFloat} =
_pow_round(IntervalRounding{:slow}(), x, y, r)

# _pow_round(::IntervalRounding{:fast}, x::T, y::T, ::RoundingMode{:Down}) where {T<:AbstractFloat} =
# prevfloat(^(x, y))
# _pow_round(::IntervalRounding{:fast}, x::T, y::T, ::RoundingMode{:Up}) where {T<:AbstractFloat} =
# nextfloat(^(x, y))

function _pow_round(::IntervalRounding{:slow}, x::T, y::T, r::RoundingMode) where {T<:AbstractFloat}
prec = max(precision(x), precision(y))
bigx = BigFloat(x; precision = prec)
Expand All @@ -76,6 +82,7 @@ function _pow_round(::IntervalRounding{:slow}, x::T, y::T, r::RoundingMode) wher
)::Int32
return bigz
end

_pow_round(::IntervalRounding{:none}, x::T, y::T, ::RoundingMode) where {T<:AbstractFloat} = ^(x, y)

#
Expand All @@ -85,14 +92,17 @@ _inv_round(x::Rational, ::RoundingMode) = inv(x) # exact operation

_inv_round(::IntervalRounding, x::AbstractFloat, r::RoundingMode) =
_inv_round(IntervalRounding{:slow}(), x, r)

# _inv_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Down}) =
# prevfloat(inv(x))
# _inv_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Up}) =
# nextfloat(inv(x))

_inv_round(::IntervalRounding{:tight}, x::Union{Float32,Float64}, ::RoundingMode{:Down}) =
RoundingEmulator.div_down(one(x), x)
_inv_round(::IntervalRounding{:tight}, x::Union{Float32,Float64}, ::RoundingMode{:Up}) =
RoundingEmulator.div_up(one(x), x)

function _inv_round(::IntervalRounding{:slow}, x::AbstractFloat, r::RoundingMode)
prec = precision(x)
bigx = BigFloat(x; precision = prec)
Expand All @@ -105,6 +115,7 @@ function _inv_round(::IntervalRounding{:slow}, x::AbstractFloat, r::RoundingMode
)::Int32
return bigz
end

_inv_round(::IntervalRounding{:none}, x::AbstractFloat, ::RoundingMode) = inv(x)

#
Expand All @@ -113,14 +124,17 @@ _sqrt_round(x::AbstractFloat, r::RoundingMode) = _sqrt_round(interval_rounding()

_sqrt_round(::IntervalRounding, x::AbstractFloat, r::RoundingMode) =
_sqrt_round(IntervalRounding{:slow}(), x, r)

# _sqrt_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Down}) =
# prevfloat(sqrt(x))
# _sqrt_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Up}) =
# nextfloat(sqrt(x))

_sqrt_round(::IntervalRounding{:tight}, x::Union{Float32,Float64}, ::RoundingMode{:Down}) =
RoundingEmulator.sqrt_down(x)
_sqrt_round(::IntervalRounding{:tight}, x::Union{Float32,Float64}, ::RoundingMode{:Up}) =
RoundingEmulator.sqrt_up(x)

function _sqrt_round(::IntervalRounding{:slow}, x::AbstractFloat, r::RoundingMode)
prec = precision(x)
bigx = BigFloat(x; precision = prec)
Expand All @@ -132,6 +146,7 @@ function _sqrt_round(::IntervalRounding{:slow}, x::AbstractFloat, r::RoundingMod
)::Int32
return bigz
end

_sqrt_round(::IntervalRounding{:none}, x::AbstractFloat, ::RoundingMode) = sqrt(x)

#
Expand All @@ -140,10 +155,12 @@ _rootn_round(x::AbstractFloat, n::Integer, r::RoundingMode) = _rootn_round(inter

_rootn_round(::IntervalRounding, x::AbstractFloat, n::Integer, r::RoundingMode) =
_rootn_round(IntervalRounding{:slow}(), x, n, r)

# _rootn_round(::IntervalRounding{:fast}, x::AbstractFloat, n::Integer, ::RoundingMode{:Down}) =
# prevfloat(x^(1//n))
# _rootn_round(::IntervalRounding{:fast}, x::AbstractFloat, n::Integer, ::RoundingMode{:Up}) =
# nextfloat(x^(1//n))

function _rootn_round(::IntervalRounding{:slow}, x::AbstractFloat, n::Integer, r::RoundingMode)
prec = precision(x)
bigx = BigFloat(x; precision = prec)
Expand All @@ -156,6 +173,7 @@ function _rootn_round(::IntervalRounding{:slow}, x::AbstractFloat, n::Integer, r
)::Int32
return bigz
end

_rootn_round(::IntervalRounding{:none}, x::AbstractFloat, n::Integer, ::RoundingMode) = x^(1//n)

#
Expand All @@ -164,10 +182,12 @@ _atan_round(x::T, y::T, r::RoundingMode) where {T<:AbstractFloat} = _atan_round(

_atan_round(::IntervalRounding, x::T, y::T, r::RoundingMode) where {T<:AbstractFloat} =
_atan_round(IntervalRounding{:slow}(), x, y, r)

# _atan_round(::IntervalRounding{:fast}, x::T, y::T, ::RoundingMode{:Down}) where {T<:AbstractFloat} =
# prevfloat(atan(x, y))
# _atan_round(::IntervalRounding{:fast}, x::T, y::T, ::RoundingMode{:Up}) where {T<:AbstractFloat} =
# nextfloat(atan(x, y))

function _atan_round(::IntervalRounding{:slow}, x::T, y::T, r::RoundingMode) where {T<:AbstractFloat}
prec = max(precision(x), precision(y))
bigx = BigFloat(x; precision = prec)
Expand All @@ -181,6 +201,7 @@ function _atan_round(::IntervalRounding{:slow}, x::T, y::T, r::RoundingMode) whe
)::Int32
return bigz
end

_atan_round(::IntervalRounding{:none}, x::T, y::T, ::RoundingMode) where {T<:AbstractFloat} = atan(x, y)

#
Expand All @@ -193,10 +214,12 @@ for f ∈ [:cbrt, :exp2, :exp10, :cot, :sec, :csc, :tanh, :coth, :sech, :csch, :
$f_round(x::AbstractFloat, r::RoundingMode) = $f_round(interval_rounding(), x, r)

$f_round(::IntervalRounding, x::AbstractFloat, r::RoundingMode) = $f_round(IntervalRounding{:slow}(), x, r)

# $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Down}) =
# prevfloat($f(x))
# $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Up}) =
# nextfloat($f(x))

function $f_round(::IntervalRounding{:slow}, x::AbstractFloat, r::RoundingMode)
prec = precision(x)
bigx = BigFloat(x; precision = prec)
Expand All @@ -208,6 +231,7 @@ for f ∈ [:cbrt, :exp2, :exp10, :cot, :sec, :csc, :tanh, :coth, :sech, :csch, :
)::Int32
return bigz
end

$f_round(::IntervalRounding{:none}, x::AbstractFloat, ::RoundingMode) = $f(x)
end
end
Expand All @@ -220,10 +244,12 @@ for (f, g) ∈ [(:acot, :atan), (:acoth, :atanh)]
$f_round(x::AbstractFloat, r::RoundingMode) = $f_round(interval_rounding(), x, r)

$f_round(::IntervalRounding, x::AbstractFloat, r::RoundingMode) = $f_round(IntervalRounding{:slow}(), x, r)

# $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Down}) =
# prevfloat($f(x))
# $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Up}) =
# nextfloat($f(x))

function $f_round(ir::IntervalRounding{:slow}, x::AbstractFloat, r::RoundingMode{:Down})
prec = precision(x)
bigx = BigFloat(x; precision = prec + 10)
Expand All @@ -250,6 +276,7 @@ for (f, g) ∈ [(:acot, :atan), (:acoth, :atanh)]
bigw = $g_round(ir, bigz, r)
return BigFloat(bigw, r; precision = prec)
end

$f_round(::IntervalRounding{:none}, x::AbstractFloat, ::RoundingMode) = $f(x)
end
end
Expand All @@ -263,15 +290,17 @@ for f ∈ [:exp, :expm1, :log, :log1p, :log2, :log10, :sin, :cos, :tan, :asin, :
crlibm_f_u = string(f, "_ru")
mpfr_f = Symbol(:mpfr_, f)

@eval $f_round(x::AbstractFloat, r::RoundingMode) = $f_round(interval_rounding(), x, r)
if Int == Int32 # issues with CRlibm for 32 bit systems, use MPFR (only available since Julia v1.10)
if VERSION v"1.10" || f (:sinpi, :cospi)
@eval $f_round(x::AbstractFloat, r::RoundingMode) = $f_round(interval_rounding(), x, r)

@eval $f_round(::IntervalRounding, x::AbstractFloat, r::RoundingMode) = $f_round(IntervalRounding{:slow}(), x, r)

# @eval $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Down}) =
# prevfloat($f(x))
# @eval $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Up}) =
# nextfloat($f(x))

@eval $f_round(::IntervalRounding, x::AbstractFloat, r::RoundingMode) = $f_round(IntervalRounding{:slow}(), x, r)
# @eval $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Down}) =
# prevfloat($f(x))
# @eval $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Up}) =
# nextfloat($f(x))
if Int == Int32 && f (:sinpi, :cospi) # issues with CRlibm for 32 bit systems, use MPFR (only available since Julia v1.10)
if VERSION v"1.10"
@eval function $f_round(::IntervalRounding{:slow}, x::AbstractFloat, r::RoundingMode)
prec = precision(x)
bigx = BigFloat(x; precision = prec)
Expand All @@ -283,8 +312,19 @@ for f ∈ [:exp, :expm1, :log, :log1p, :log2, :log10, :sin, :cos, :tan, :asin, :
)::Int32
return bigz
end

@eval $f_round(::IntervalRounding{:none}, x::AbstractFloat, ::RoundingMode) = $f(x)
end
else
@eval $f_round(x::AbstractFloat, r::RoundingMode) = $f_round(interval_rounding(), x, r)

@eval $f_round(::IntervalRounding, x::AbstractFloat, r::RoundingMode) = $f_round(IntervalRounding{:slow}(), x, r)

# @eval $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Down}) =
# prevfloat($f(x))
# @eval $f_round(::IntervalRounding{:fast}, x::AbstractFloat, ::RoundingMode{:Up}) =
# nextfloat($f(x))

@eval $f_round(::IntervalRounding{:tight}, x::Float16, r::RoundingMode) = Float16($f_round(Float64(x), r), r)
@eval $f_round(::IntervalRounding{:tight}, x::Float32, r::RoundingMode) = Float32($f_round(Float64(x), r), r)
@eval $f_round(::IntervalRounding{:tight}, x::Float64, r::RoundingMode{:Down}) = ccall(($crlibm_f_d, CRlibm_jll.libcrlibm), Float64, (Float64,), x)
Expand All @@ -301,8 +341,9 @@ for f ∈ [:exp, :expm1, :log, :log1p, :log2, :log10, :sin, :cos, :tan, :asin, :
)::Int32
return bigz
end

@eval $f_round(::IntervalRounding{:none}, x::AbstractFloat, ::RoundingMode) = $f(x)
end
@eval $f_round(::IntervalRounding{:none}, x::AbstractFloat, ::RoundingMode) = $f(x)
end
end

Expand Down
24 changes: 13 additions & 11 deletions test/interval_tests/trigonometric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ end
@test isthin(cosd(interval(270)), 0)
end

@testset "sincospi" begin
x = sincospi(emptyinterval())
@test isempty_interval(x[1]) & isempty_interval(x[2])
x = sincospi(interval(1, 2))
@test issubset_interval(interval(-1, 0), x[1]) & isequal_interval(x[2], interval(-1, 1))
x = sincospi(interval(0.5, 1.5))
@test isequal_interval(x[1], interval(-1, 1)) & issubset_interval(interval(-1, 0), x[2])
x = sincospi(interval(0.25, 0.75))
@test issubset_interval(interval(1/sqrt(2), 1), x[1]) & issubset_interval(interval(-1/sqrt(2), 1/sqrt(2)), x[2])
x = sincospi(interval(-0.25, 0.25))
@test issubset_interval(interval(-1/sqrt(2), 1/sqrt(2)), x[1]) & isequal_interval(x[2], interval(1/sqrt(2), 1))
if (Int != Int32 && VERSION < v"1.10") || VERSION v"1.10"
@testset "sincospi" begin
x = sincospi(emptyinterval())
@test isempty_interval(x[1]) & isempty_interval(x[2])
x = sincospi(interval(1, 2))
@test issubset_interval(interval(-1, 0), x[1]) & isequal_interval(x[2], interval(-1, 1))
x = sincospi(interval(0.5, 1.5))
@test isequal_interval(x[1], interval(-1, 1)) & issubset_interval(interval(-1, 0), x[2])
x = sincospi(interval(0.25, 0.75))
@test issubset_interval(interval(1/sqrt(2), 1), x[1]) & issubset_interval(interval(-1/sqrt(2), 1/sqrt(2)), x[2])
x = sincospi(interval(-0.25, 0.25))
@test issubset_interval(interval(-1/sqrt(2), 1/sqrt(2)), x[1]) & isequal_interval(x[2], interval(1/sqrt(2), 1))
end
end

@testset "sincosd" begin
Expand Down

0 comments on commit b4eef85

Please sign in to comment.