diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index c44bb1d55..15e978fe2 100644 --- a/src/IntervalArithmetic.jl +++ b/src/IntervalArithmetic.jl @@ -62,7 +62,7 @@ export midpoint_radius, interval_from_midpoint_radius, RoundTiesToEven, RoundTiesToAway, cancelminus, cancelplus, isunbounded, - .., @I_str, ±, + .., @I_str, ±, reciprocal_sqrt, pow, extended_div, setformat, @format diff --git a/src/intervals/functions.jl b/src/intervals/functions.jl index c27bbc9b1..2664cb2ba 100644 --- a/src/intervals/functions.jl +++ b/src/intervals/functions.jl @@ -305,3 +305,12 @@ for f in (:log, :log2, :log10, :log1p) end end + +#computes the reciprocal of square root of an Interval +function reciprocal_sqrt(a::Interval{T}) where T + x = sqrt(a) + isempty(x) && return emptyinterval(x) + x.lo == zero(T) < x.hi && return @round(inv(x.hi), T(Inf)) + x == zero(x) && return emptyinterval(T) + @round(inv(x.hi), inv(x.lo)) +end diff --git a/test/ITF1788_tests/libieeep1788_tests_elem.jl b/test/ITF1788_tests/libieeep1788_tests_elem.jl index e26df7722..db03226a3 100644 --- a/test/ITF1788_tests/libieeep1788_tests_elem.jl +++ b/test/ITF1788_tests/libieeep1788_tests_elem.jl @@ -995,6 +995,20 @@ end @test decoration((DecoratedInterval(Interval(-5.0, Inf), dac))^(1//2)) == decoration(DecoratedInterval(Interval(0.0, Inf), trv)) end +@testset "minimal_rsqrt_test" begin + @test reciprocal_sqrt(∅) == ∅ + @test reciprocal_sqrt(Interval(-Inf, Inf)) == 0 .. Inf + @test reciprocal_sqrt(Interval(-Inf, -0x0.0000000000001p-1022)) == ∅ + @test reciprocal_sqrt(Interval(-1.0, 1.0)) == 1.0 .. Inf + @test reciprocal_sqrt(Interval(0.0, 1.0)) == 1.0 .. Inf + @test reciprocal_sqrt(Interval(-0.0, 1.0)) == 1.0 .. Inf + @test reciprocal_sqrt(Interval(-5.0, 25.0)) == 0.2 .. Inf + @test reciprocal_sqrt(Interval(0.0, 25.0)) == 0.2 .. Inf + @test reciprocal_sqrt(Interval(-0.0, 25.0)) == 0.2 .. Inf + @test reciprocal_sqrt(Interval(-5.0, Inf)) == 0.0 .. Inf + @test reciprocal_sqrt(Interval(4.0, 25.0)) == 0.2 .. 0.5 +end + @testset "minimal_fma_test" begin @test fma(∅, ∅, ∅) == ∅ @test fma(Interval(-1.0, 1.0), ∅, ∅) == ∅