Skip to content

Commit

Permalink
Fix sqrt and inv for BigFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed Dec 10, 2018
1 parent 502f07d commit 86a0848
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/intervals/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ for (op, f) in ( (:+, :add), (:-, :sub), (:*, :mul), (:/, :div) )
end

# inv and sqrt:

# inv(::IntervalRounding{:tight}, a::T, r::RoundingMode) where T<:Union{Float32, Float64} = inv_round(a, r)
#
# sqrt(::IntervalRounding{:tight}, a::T, r::RoundingMode) where T<:Union{Float32, Float64} = sqrt_round(a, r)


for T in (Float32, Float64)
for mode in (:Down, :Up)

Expand Down Expand Up @@ -176,13 +182,19 @@ for mode in (:Down, :Up)
# functions not in CRlibm:
for f in (:sqrt, :inv, :tanh, :asinh, :acosh, :atanh)


@eval function $f(::IntervalRounding{:slow},
a::T, $mode1) where T<:AbstractFloat
setrounding(T, $mode2) do
$f(a)
end
end

@eval function $f(::IntervalRounding{:tight},
a::T, $mode1) where T<:AbstractFloat
$f(IntervalRounding{:slow}(), a, $mode2)
end


@eval $f(::IntervalRounding{:accurate},
a::T, $mode1) where {T<:AbstractFloat} = $directed($f(a))
Expand Down Expand Up @@ -232,16 +244,16 @@ function _setrounding(::Type{Interval}, rounding_type::Symbol)

# unary functions:

for f in (:sqrt, :inv)
@eval $f(a::T, r::RoundingMode) where {T<:AbstractFloat} = $f($roundtype, a, r)
end


if rounding_type == :tight # for remaining functions, use CRlibm
roundtype = IntervalRounding{:slow}()
end


for f in (:sqrt, :inv)
@eval $f(a::T, r::RoundingMode) where {T<:AbstractFloat} = $f($roundtype, a, r)
end

for f in (:^, :atan)

@eval $f(a::T, b::T, r::RoundingMode) where {T<:AbstractFloat} = $f($roundtype, a, b, r)
Expand Down

0 comments on commit 86a0848

Please sign in to comment.