From 0b4f8c3a338eea3906a3036b06265c191fac9471 Mon Sep 17 00:00:00 2001 From: yashrajgupta Date: Tue, 12 Mar 2019 23:48:52 +0530 Subject: [PATCH 1/2] Add rsqrt function and test cases --- src/IntervalArithmetic.jl | 2 +- src/intervals/functions.jl | 8 ++++++++ test/ITF1788_tests/libieeep1788_tests_elem.jl | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index c44bb1d55..ee372fe7f 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, ±, rsqrt, pow, extended_div, setformat, @format diff --git a/src/intervals/functions.jl b/src/intervals/functions.jl index c27bbc9b1..eac8f3604 100644 --- a/src/intervals/functions.jl +++ b/src/intervals/functions.jl @@ -305,3 +305,11 @@ for f in (:log, :log2, :log10, :log1p) end end + +function rsqrt(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..bd8b8095e 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 rsqrt(∅) == ∅ + @test rsqrt(Interval(-Inf, Inf)) == 0 .. Inf + @test rsqrt(Interval(-Inf, -0x0.0000000000001p-1022)) == ∅ + @test rsqrt(Interval(-1.0, 1.0)) == 1.0 .. Inf + @test rsqrt(Interval(0.0, 1.0)) == 1.0 .. Inf + @test rsqrt(Interval(-0.0, 1.0)) == 1.0 .. Inf + @test rsqrt(Interval(-5.0, 25.0)) == 0.2 .. Inf + @test rsqrt(Interval(0.0, 25.0)) == 0.2 .. Inf + @test rsqrt(Interval(-0.0, 25.0)) == 0.2 .. Inf + @test rsqrt(Interval(-5.0, Inf)) == 0.0 .. Inf + @test rsqrt(Interval(4.0, 25.0)) == 0.2 .. 0.5 +end + @testset "minimal_fma_test" begin @test fma(∅, ∅, ∅) == ∅ @test fma(Interval(-1.0, 1.0), ∅, ∅) == ∅ From 5b302fb59839248b7feca64bf8b1aaa1357b9021 Mon Sep 17 00:00:00 2001 From: yashrajgupta Date: Sat, 13 Apr 2019 02:06:22 +0530 Subject: [PATCH 2/2] Change name of rsqrt function and add doc string --- src/IntervalArithmetic.jl | 2 +- src/intervals/functions.jl | 3 ++- test/ITF1788_tests/libieeep1788_tests_elem.jl | 22 +++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index ee372fe7f..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, ±, rsqrt, + .., @I_str, ±, reciprocal_sqrt, pow, extended_div, setformat, @format diff --git a/src/intervals/functions.jl b/src/intervals/functions.jl index eac8f3604..2664cb2ba 100644 --- a/src/intervals/functions.jl +++ b/src/intervals/functions.jl @@ -306,7 +306,8 @@ for f in (:log, :log2, :log10, :log1p) end end -function rsqrt(a::Interval{T}) where T +#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)) diff --git a/test/ITF1788_tests/libieeep1788_tests_elem.jl b/test/ITF1788_tests/libieeep1788_tests_elem.jl index bd8b8095e..db03226a3 100644 --- a/test/ITF1788_tests/libieeep1788_tests_elem.jl +++ b/test/ITF1788_tests/libieeep1788_tests_elem.jl @@ -996,17 +996,17 @@ end end @testset "minimal_rsqrt_test" begin - @test rsqrt(∅) == ∅ - @test rsqrt(Interval(-Inf, Inf)) == 0 .. Inf - @test rsqrt(Interval(-Inf, -0x0.0000000000001p-1022)) == ∅ - @test rsqrt(Interval(-1.0, 1.0)) == 1.0 .. Inf - @test rsqrt(Interval(0.0, 1.0)) == 1.0 .. Inf - @test rsqrt(Interval(-0.0, 1.0)) == 1.0 .. Inf - @test rsqrt(Interval(-5.0, 25.0)) == 0.2 .. Inf - @test rsqrt(Interval(0.0, 25.0)) == 0.2 .. Inf - @test rsqrt(Interval(-0.0, 25.0)) == 0.2 .. Inf - @test rsqrt(Interval(-5.0, Inf)) == 0.0 .. Inf - @test rsqrt(Interval(4.0, 25.0)) == 0.2 .. 0.5 + @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