8
8
9
9
+ (a:: Interval ) = a # Not in the IEEE standard
10
10
11
- """
12
- -(a::Interval)
13
-
14
- Implement the `neg` function of the IEEE Std 1788-2015 (Table 9.1).
15
- """
16
- - (a:: F ) where {F<: Interval } = F (- sup (a), - inf (a))
17
-
18
-
19
11
"""
20
12
+(a::Interval, b::Real)
21
- +(a::Real, a ::Interval)
13
+ +(a::Real, b ::Interval)
22
14
+(a::Interval, b::Interval)
23
15
24
16
Implement the `add` function of the IEEE Std 1788-2015 (Table 9.1).
@@ -34,10 +26,18 @@ function +(a::F, b::F) where {F<:Interval}
34
26
(isempty (a) || isempty (b)) && return emptyinterval (F)
35
27
return @round (F, inf (a) + inf (b), sup (a) + sup (b))
36
28
end
29
+ + (a:: Interval , b:: Interval ) = + (promote (a, b)... )
30
+
31
+ """
32
+ -(a::Interval)
33
+
34
+ Implement the `neg` function of the IEEE Std 1788-2015 (Table 9.1).
35
+ """
36
+ - (a:: F ) where {F<: Interval } = F (- sup (a), - inf (a))
37
37
38
38
"""
39
39
-(a::Interval, b::Real)
40
- -(a::Real, a ::Interval)
40
+ -(a::Real, b ::Interval)
41
41
-(a::Interval, b::Interval)
42
42
43
43
Implement the `sub` function of the IEEE Std 1788-2015 (Table 9.1).
@@ -46,19 +46,18 @@ function -(a::F, b::T) where {T<:Real, F<:Interval{T}}
46
46
isempty (a) && return emptyinterval (F)
47
47
return @round (F, inf (a) - b, sup (a) - b)
48
48
end
49
-
50
49
function - (b:: T , a:: F ) where {T, F<: Interval{T} }
51
50
isempty (a) && return emptyinterval (F)
52
51
return @round (F, b - sup (a), b - inf (a))
53
52
end
53
+ - (a:: F , b:: Real ) where {F<: Interval } = a - F (b)
54
+ - (a:: Real , b:: F ) where {F<: Interval } = F (a) - b
54
55
55
56
function - (a:: F , b:: F ) where {F<: Interval }
56
57
(isempty (a) || isempty (b)) && return emptyinterval (F)
57
58
return @round (F, inf (a) - sup (b), sup (a) - inf (b))
58
59
end
59
-
60
- - (a:: F , b:: Real ) where {F<: Interval } = a - F (b)
61
- - (a:: Real , b:: F ) where {F<: Interval } = F (a) - b
60
+ - (a:: Interval , b:: Interval ) = - (promote (a, b)... )
62
61
63
62
"""
64
63
scale(α, a::Interval)
@@ -71,7 +70,7 @@ For efficiency, does not check that the constant is positive.
71
70
72
71
"""
73
72
*(a::Interval, b::Real)
74
- *(a::Real, a ::Interval)
73
+ *(a::Real, b ::Interval)
75
74
*(a::Interval, b::Interval)
76
75
77
76
Implement the `mul` function of the IEEE Std 1788-2015 (Table 9.1).
@@ -88,37 +87,33 @@ function *(x::T, a::F) where {T<:Real, F<:Interval{T}}
88
87
return @round (F, sup (a)* x, inf (a)* x)
89
88
end
90
89
end
91
-
92
90
* (x:: T , a:: F ) where {T<: Real , S, F<: Interval{S} } = Interval {S} (x) * a
93
91
* (a:: F , x:: T ) where {T<: Real , S, F<: Interval{S} } = x* a
94
92
95
93
function * (a:: F , b:: F ) where {F<: Interval }
96
94
(isempty (a) || isempty (b)) && return emptyinterval (F)
97
-
98
95
(isthinzero (a) || isthinzero (b)) && return zero (F)
99
-
100
96
(isbounded (a) && isbounded (b)) && return mult (* , a, b)
101
-
102
97
return mult ((x, y, r) -> unbounded_mult (F, x, y, r), a, b)
103
98
end
104
-
99
+ * (a :: Interval , b :: Interval ) = * ( promote (a, b) ... )
105
100
106
101
# Helper functions for multiplication
107
102
function unbounded_mult (:: Type{F} , x:: T , y:: T , r:: RoundingMode ) where {T, F<: Interval{T} }
108
- iszero (x) && return sign (y)* zero_times_infinity (T)
109
- iszero (y) && return sign (x)* zero_times_infinity (T)
103
+ iszero (x) && return sign (y) * zero_times_infinity (T)
104
+ iszero (y) && return sign (x) * zero_times_infinity (T)
110
105
return * (x, y, r)
111
106
end
112
107
113
108
function mult (op, a:: F , b:: F ) where {T, F<: Interval{T} }
114
109
if inf (b) >= zero (T)
115
110
inf (a) >= zero (T) && return @round (F, op (inf (a), inf (b)), op (sup (a), sup (b)))
116
111
sup (a) <= zero (T) && return @round (F, op (inf (a), sup (b)), op (sup (a), inf (b)))
117
- return @round (F, inf (a)* sup (b), sup (a)* sup (b)) # when zero(T) ∈ a
112
+ return @round (F, inf (a)* sup (b), sup (a)* sup (b)) # zero(T) ∈ a
118
113
elseif sup (b) <= zero (T)
119
114
inf (a) >= zero (T) && return @round (F, op (sup (a), inf (b)), op (inf (a), sup (b)))
120
115
sup (a) <= zero (T) && return @round (F, op (sup (a), sup (b)), op (inf (a), inf (b)))
121
- return @round (F, sup (a)* inf (b), inf (a)* inf (b)) # when zero(T) ∈ a
116
+ return @round (F, sup (a)* inf (b), inf (a)* inf (b)) # zero(T) ∈ a
122
117
else
123
118
inf (a) > zero (T) && return @round (F, op (sup (a), inf (b)), op (sup (a), sup (b)))
124
119
sup (a) < zero (T) && return @round (F, op (inf (a), sup (b)), op (inf (a), inf (b)))
129
124
130
125
"""
131
126
/(a::Interval, b::Real)
132
- /(a::Real, a ::Interval)
127
+ /(a::Real, b ::Interval)
133
128
/(a::Interval, b::Interval)
134
129
135
130
Implement the `div` function of the IEEE Std 1788-2015 (Table 9.1).
@@ -182,6 +177,7 @@ function /(a::F, b::F) where {T, F<:Interval{T}}
182
177
end
183
178
end
184
179
end
180
+ / (a:: Interval , b:: Interval ) = / (promote (a, b)... )
185
181
186
182
"""
187
183
inv(a::Interval)
0 commit comments