Skip to content

Commit 0b4f8c3

Browse files
committed
Add rsqrt function and test cases
1 parent 1516c5e commit 0b4f8c3

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/IntervalArithmetic.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export
6262
midpoint_radius, interval_from_midpoint_radius,
6363
RoundTiesToEven, RoundTiesToAway,
6464
cancelminus, cancelplus, isunbounded,
65-
.., @I_str, ±,
65+
.., @I_str, ±, rsqrt,
6666
pow, extended_div,
6767
setformat, @format
6868

src/intervals/functions.jl

+8
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,11 @@ for f in (:log, :log2, :log10, :log1p)
305305

306306
end
307307
end
308+
309+
function rsqrt(a::Interval{T}) where T
310+
x = sqrt(a)
311+
isempty(x) && return emptyinterval(x)
312+
x.lo == zero(T) < x.hi && return @round(inv(x.hi), T(Inf))
313+
x == zero(x) && return emptyinterval(T)
314+
@round(inv(x.hi), inv(x.lo))
315+
end

test/ITF1788_tests/libieeep1788_tests_elem.jl

+14
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,20 @@ end
995995
@test decoration((DecoratedInterval(Interval(-5.0, Inf), dac))^(1//2)) == decoration(DecoratedInterval(Interval(0.0, Inf), trv))
996996
end
997997

998+
@testset "minimal_rsqrt_test" begin
999+
@test rsqrt(∅) == ∅
1000+
@test rsqrt(Interval(-Inf, Inf)) == 0 .. Inf
1001+
@test rsqrt(Interval(-Inf, -0x0.0000000000001p-1022)) == ∅
1002+
@test rsqrt(Interval(-1.0, 1.0)) == 1.0 .. Inf
1003+
@test rsqrt(Interval(0.0, 1.0)) == 1.0 .. Inf
1004+
@test rsqrt(Interval(-0.0, 1.0)) == 1.0 .. Inf
1005+
@test rsqrt(Interval(-5.0, 25.0)) == 0.2 .. Inf
1006+
@test rsqrt(Interval(0.0, 25.0)) == 0.2 .. Inf
1007+
@test rsqrt(Interval(-0.0, 25.0)) == 0.2 .. Inf
1008+
@test rsqrt(Interval(-5.0, Inf)) == 0.0 .. Inf
1009+
@test rsqrt(Interval(4.0, 25.0)) == 0.2 .. 0.5
1010+
end
1011+
9981012
@testset "minimal_fma_test" begin
9991013
@test fma(∅, ∅, ∅) == ∅
10001014
@test fma(Interval(-1.0, 1.0), ∅, ∅) == ∅

0 commit comments

Comments
 (0)