Skip to content

Commit

Permalink
Merge pull request #393 from krish8484/cxsc
Browse files Browse the repository at this point in the history
Completes c-xsc.jl
  • Loading branch information
Kolaru committed Sep 6, 2020
2 parents d3a318c + 3b43a9d commit a1cbb81
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/IntervalArithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export
interval,
@interval, @biginterval, @floatinterval, @make_interval,
diam, radius, mid, mag, mig, hull,
emptyinterval, ∅, ∞, isempty, isinterior, ,
emptyinterval, ∅, ∞, isempty, isinterior, , nthroot,
precedes, strictprecedes, , , , , , contains_zero,
entireinterval, isentire, nai, isnai, isthin, iscommon, isatomic,
widen, inf, sup, bisect, mince,
Expand Down
33 changes: 33 additions & 0 deletions src/intervals/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ for f in (:exp, :expm1)
end
end


for f in (:exp2, :exp10, :cbrt)

@eval function ($f)(x::BigFloat, r::RoundingMode) # add BigFloat functions with rounding:
Expand Down Expand Up @@ -327,3 +328,35 @@ end
hypot(a::Interval{BigFloat}, b::Interval{BigFloat}) = sqrt(a^2 + b^2)

hypot(a::Interval{T}, b::Interval{T}) where T= atomic(Interval{T}, hypot(big53(a), big53(b)))

"""
nthroot(a::Interval{BigFloat}, n::Integer)
Compute the real n-th root of Interval.
"""
function nthroot(a::Interval{BigFloat}, n::Integer)
n == 1 && return a
n < 0 && a == zero(a) && return emptyinterval(a)
isempty(a) && return a
if n > 0
a.hi < 0 && iseven(n) && return emptyinterval(BigFloat)
if a.lo < 0 && a.hi >= 0 && iseven(n)
a = a Interval{BigFloat}(0, Inf)
end
ui = convert(Culong, n)
low = BigFloat()
high = BigFloat()
ccall((:mpfr_rootn_ui, :libmpfr), Int32 , (Ref{BigFloat}, Ref{BigFloat}, Culong, MPFRRoundingMode) , low , a.lo , ui, MPFRRoundDown)
ccall((:mpfr_rootn_ui, :libmpfr), Int32 , (Ref{BigFloat}, Ref{BigFloat}, Culong, MPFRRoundingMode) , high , a.hi , ui, MPFRRoundUp)
b = interval(low , high)
return b
elseif n < 0
return inv(nthroot(a, -n))
elseif n == 0
return emptyinterval(a)
end
end

function nthroot(a::Interval{T}, n::Integer) where T
b = nthroot(big53(a), n)
return convert(Interval{T}, b)
end
1 change: 1 addition & 0 deletions test/ITF1788_tests/ITF1788_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ include("libieeep1788_tests_rev.jl")
include("libieeep1788_tests_set.jl")
include("mpfi.jl")
include("fi_lib.jl")
include("c-xsc.jl")

0 comments on commit a1cbb81

Please sign in to comment.