Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHnt committed Nov 18, 2023
1 parent 5991c5b commit 9c1283e
Show file tree
Hide file tree
Showing 10 changed files with 611 additions and 552 deletions.
3 changes: 1 addition & 2 deletions src/IntervalArithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using SetRounding
using EnumX

import Base:
+, -, *, /, inv, //, muladd, fma, sqrt,
+, -, *, /, \, inv, //, muladd, fma, sqrt,
sinh, cosh, tanh, coth, csch, sech, asinh, acosh, atanh, acoth,
rad2deg, deg2rad, sin, cos, tan, cot, csc, sec, asin, acos, atan, acot, sinpi, cospi, sincospi,
exp, log, exp2, exp10, log2, log10, cbrt, hypot, ^,
Expand Down Expand Up @@ -48,7 +48,6 @@ export BareInterval, bareinterval, Interval, interval, decoration, @I_str,
entireinterval, isentire_interval, nai, isnai, iscommon, isatomic,
inf, sup, bounds, mince,
dist,
RoundTiesToEven, RoundTiesToAway,
IntervalRounding,
cancelminus, cancelplus,
fastpow, extended_div, nthroot, nthpow,
Expand Down
66 changes: 27 additions & 39 deletions src/intervals/arithmetic/absmax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# 9.1 of the IEEE Standard 1788-2015 and required for set-based flavor in
# Section 10.5.3



# bare intervals

"""
abs(a::BareInterval)
abs(a::Interval)
Implement the `abs` function of the IEEE Standard 1788-2015 (Table 9.1).
Expand All @@ -16,47 +13,38 @@ function abs(a::BareInterval{T}) where {T<:NumTypes}
return _unsafe_bareinterval(T, mig(a), mag(a))
end

abs2(a::BareInterval) = nthpow(a, 2)
abs(a::Interval) = _unsafe_interval(abs(bareinterval(a)), decoration(a), guarantee(a))

"""
min(a::Interval, b::Interval)
abs2(a::BareInterval)
abs2(a::Interval)
Implement the `min` function of the IEEE Standard 1788-2015 (Table 9.1).
Implement the square absolute value; this is semantically equivalent to `nthpow(a, 2)`.
"""
function min(a::BareInterval{T}, b::BareInterval{T}) where {T<:NumTypes}
isempty_interval(a) && return a
isempty_interval(b) && return b
return _unsafe_bareinterval(T, min(inf(a), inf(b)), min(sup(a), sup(b)))
end
abs2(a::BareInterval) = nthpow(a, 2) # not in the IEEE Standard 1788-2015

min(a::BareInterval, b::BareInterval) = min(promote(a, b)...)

"""
max(a::Interval, b::Interval)
Implement the `max` function of the IEEE Standard 1788-2015 (Table 9.1).
"""
function max(a::BareInterval{T}, b::BareInterval{T}) where {T<:NumTypes}
isempty_interval(a) && return a
isempty_interval(b) && return b
return _unsafe_bareinterval(T, max(inf(a), inf(b)), max(sup(a), sup(b)))
end

max(a::BareInterval, b::BareInterval) = max(promote(a, b)...)



# decorated intervals

for f (:abs, :abs2)
@eval $f(a::Interval) = _unsafe_interval($f(bareinterval(a)), decoration(a), guarantee(a))
end
abs2(a::Interval) = _unsafe_interval(abs2(bareinterval(a)), decoration(a), guarantee(a))

for f (:min, :max)
@eval function $f(a::Interval, b::Interval)
r = $f(bareinterval(a), bareinterval(b))
d = min(decoration(a), decoration(b))
t = guarantee(a) & guarantee(b)
return _unsafe_interval(r, d, t)
@eval begin
"""
$($f)(a::BareInterval, b::BareInterval)
$($f)(a::Interval, b::Interval)
Implement the `$($f)` function of the IEEE Standard 1788-2015 (Table 9.1).
"""
function $f(a::BareInterval{T}, b::BareInterval{T}) where {T<:NumTypes}
isempty_interval(a) && return a
isempty_interval(b) && return b
return _unsafe_bareinterval(T, $f(inf(a), inf(b)), $f(sup(a), sup(b)))
end
$f(a::BareInterval, b::BareInterval) = $f(promote(a, b)...)

function $f(a::Interval, b::Interval)
r = $f(bareinterval(a), bareinterval(b))
d = min(decoration(a), decoration(b))
t = guarantee(a) & guarantee(b)
return _unsafe_interval(r, d, t)
end
end
end
Loading

0 comments on commit 9c1283e

Please sign in to comment.