-
Notifications
You must be signed in to change notification settings - Fork 70
/
IntervalArithmetic.jl
137 lines (99 loc) · 3.16 KB
/
IntervalArithmetic.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# This file is part of the IntervalArithmetic.jl package; MIT licensed
module IntervalArithmetic
import CRlibm
using StaticArrays
using FastRounding
using SetRounding
using RoundingEmulator
using Markdown
using LinearAlgebra
import LinearAlgebra: ×, dot, norm
export ×, dot
import Base:
+, -, *, /, //, fma,
<, >, ==, !=, ⊆, ^, <=,
in, zero, one, eps, typemin, typemax, abs, abs2, real, min, max,
sqrt, exp, log, sin, cos, tan, cot, inv, cbrt, csc, hypot, sec,
exp2, exp10, log2, log10,
mod,
asin, acos, atan,
sinh, cosh, tanh, coth, csch, sech, asinh, acosh, atanh, sinpi, cospi,
union, intersect, isempty,
convert, promote_rule, eltype, size,
BigFloat, float, widen, big,
∩, ∪, ⊆, ⊇, ∈, eps,
floor, ceil, trunc, sign, round, copysign, flipsign, signbit,
expm1, log1p,
precision,
isfinite, isnan, isinf, iszero,
abs, abs2,
show,
isinteger, setdiff,
parse, hash
import Base: # for IntervalBox
broadcast, length,
getindex, setindex,
iterate, eltype
import Base.MPFR: MPFRRoundingMode
import Base.MPFR: MPFRRoundUp, MPFRRoundDown, MPFRRoundNearest, MPFRRoundToZero, MPFRRoundFromZero
import .Broadcast: broadcasted
export
AbstractInterval, Interval,
interval,
@interval, @biginterval, @floatinterval,
diam, radius, mid, mag, mig, hull,
emptyinterval, ∅, ∞, isempty, isinterior, ⪽, nthroot,
precedes, strictprecedes, ≼, ≺, ⊂, ⊃, ⊇, contains_zero,
entireinterval, isentire, nai, isnai, isthin, iscommon, isatomic,
widen, inf, sup, bisect, mince,
parameters, eps, dist, #numtype,
midpoint_radius, interval_from_midpoint_radius,
RoundTiesToEven, RoundTiesToAway,
cancelminus, cancelplus, isunbounded,
.., @I_str, ±,
pow, extended_div,
setformat, @format
import Base: isdisjoint
export
setindex # re-export from StaticArrays for IntervalBox
export showfull
import Base: rounding, setrounding, setprecision
## Multidimensional
export
IntervalBox, symmetric_box
## Decorations
export
@decorated,
interval, decoration, DecoratedInterval,
com, dac, def, trv, ill
## Union type
export
Region
function __init__()
setrounding(BigFloat, RoundNearest)
setprecision(Interval, 256) # set up pi
setprecision(Interval, Float64)
end
## Includes
include("intervals/intervals.jl")
include("multidim/multidim.jl")
include("bisect.jl")
include("decorations/decorations.jl")
include("rand.jl")
include("parsing.jl")
include("display.jl")
include("plot_recipes/plot_recipes.jl")
include("deprecated.jl")
"""
Region{T} = Union{Interval{T}, IntervalBox{T}}
"""
const Region{T} = Union{Interval{T}, IntervalBox{T}}
# These definitions has been put there because generated functions must be
# defined after all methods they use.
@generated function Interval{T}(x::AbstractIrrational) where T
res = atomic(Interval{T}, x()) # Precompute the interval
return :(return $res) # Set body of the function to return the precomputed result
end
Interval{BigFloat}(x::AbstractIrrational) = atomic(Interval{BigFloat}, x)
Interval(x::AbstractIrrational) = Interval{Float64}(x)
end # module IntervalArithmetic