Skip to content

Commit b6fcc80

Browse files
committed
Add rsqrt function and test cases
1 parent 9a38d80 commit b6fcc80

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/IntervalArithmetic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export
5959
midpoint_radius, interval_from_midpoint_radius,
6060
RoundTiesToEven, RoundTiesToAway,
6161
cancelminus, cancelplus, isunbounded,
62-
.., @I_str, ±,
62+
.., @I_str, ±, rsqrt,
6363
pow, extended_div,
6464
setformat, @format
6565

src/intervals/functions.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,11 @@ for f in (:log, :log2, :log10, :log1p)
269269

270270
end
271271
end
272+
273+
function rsqrt(a::Interval{T}) where T
274+
x = sqrt(a)
275+
isempty(x) && return emptyinterval(x)
276+
x.lo == zero(T) < x.hi && return @round(inv(x.hi), T(Inf))
277+
x == zero(x) && return emptyinterval(T)
278+
@round(inv(x.hi), inv(x.lo))
279+
end

test/ITF1788_tests/libieeep1788_tests_elem.jl

Lines changed: 14 additions & 0 deletions
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)