15
15
16
16
Implement the `add` function of the IEEE Std 1788-2015 (Table 9.1).
17
17
"""
18
- function + (a:: F , b:: T ) where {T, F<: Interval{T} }
18
+ function + (a:: F , b:: T ) where {T<: NumTypes , F<: Interval{T} }
19
19
isempty (a) && return emptyinterval (F)
20
20
return @round (F, inf (a) + b, sup (a) + b)
21
21
end
22
- + (a:: Interval{T} , b:: Real ) where {T} = a + interval (T, b)
23
- + (a:: Real , b:: Interval{T} ) where {T} = b + a
22
+ + (a:: Interval{T} , b:: Real ) where {T<: NumTypes } = a + interval (T, b)
23
+ + (a:: Real , b:: Interval{T} ) where {T<: NumTypes } = b + a
24
24
25
25
function + (a:: F , b:: F ) where {F<: Interval }
26
26
(isempty (a) || isempty (b)) && return emptyinterval (F)
@@ -42,16 +42,16 @@ Implement the `neg` function of the IEEE Std 1788-2015 (Table 9.1).
42
42
43
43
Implement the `sub` function of the IEEE Std 1788-2015 (Table 9.1).
44
44
"""
45
- function - (a:: F , b:: T ) where {T<: Real , F<: Interval{T} }
45
+ function - (a:: F , b:: T ) where {T<: NumTypes , 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
- function - (b:: T , a:: F ) where {T, F<: Interval{T} }
49
+ function - (b:: T , a:: F ) where {T<: NumTypes , F<: Interval{T} }
50
50
isempty (a) && return emptyinterval (F)
51
51
return @round (F, b - sup (a), b - inf (a))
52
52
end
53
- - (a:: Interval{T} , b:: Real ) where {T} = a - interval (T, b)
54
- - (a:: Real , b:: Interval{T} ) where {T} = interval (T, a) - b
53
+ - (a:: Interval{T} , b:: Real ) where {T<: NumTypes } = a - interval (T, b)
54
+ - (a:: Real , b:: Interval{T} ) where {T<: NumTypes } = interval (T, a) - b
55
55
56
56
function - (a:: F , b:: F ) where {F<: Interval }
57
57
(isempty (a) || isempty (b)) && return emptyinterval (F)
@@ -77,7 +77,7 @@ Implement the `mul` function of the IEEE Std 1788-2015 (Table 9.1).
77
77
78
78
Note: the behavior of the multiplication is flavor dependent for some edge cases.
79
79
"""
80
- function * (a:: F , b:: T ) where {T<: Real , F<: Interval{T} }
80
+ function * (a:: F , b:: T ) where {T<: NumTypes , F<: Interval{T} }
81
81
isempty (a) && return emptyinterval (F)
82
82
(isthinzero (a) || iszero (b)) && return zero (F)
83
83
@@ -87,8 +87,8 @@ function *(a::F, b::T) where {T<:Real, F<:Interval{T}}
87
87
return @round (F, sup (a)* b, inf (a)* b)
88
88
end
89
89
end
90
- * (a:: Interval{T} , b:: Real ) where {T} = a * interval (T, b)
91
- * (a:: Real , b:: Interval{T} ) where {T} = b * a
90
+ * (a:: Interval{T} , b:: Real ) where {T<: NumTypes } = a * interval (T, b)
91
+ * (a:: Real , b:: Interval{T} ) where {T<: NumTypes } = b * a
92
92
93
93
function * (a:: F , b:: F ) where {F<: Interval }
94
94
(isempty (a) || isempty (b)) && return emptyinterval (F)
99
99
* (a:: Interval , b:: Interval ) = * (promote (a, b)... )
100
100
101
101
# Helper functions for multiplication
102
- function unbounded_mult (:: Type{F} , x:: T , y:: T , r:: RoundingMode ) where {T, F<: Interval{T} }
102
+ function unbounded_mult (:: Type{F} , x:: T , y:: T , r:: RoundingMode ) where {T<: NumTypes , F<: Interval{T} }
103
103
iszero (x) && return sign (y) * zero_times_infinity (T)
104
104
iszero (y) && return sign (x) * zero_times_infinity (T)
105
105
return * (x, y, r)
106
106
end
107
107
108
- function mult (op, a:: F , b:: F ) where {T, F<: Interval{T} }
108
+ function mult (op, a:: F , b:: F ) where {T<: NumTypes , F<: Interval{T} }
109
109
if inf (b) >= zero (T)
110
110
inf (a) >= zero (T) && return @round (F, op (inf (a), inf (b)), op (sup (a), sup (b)))
111
111
sup (a) <= zero (T) && return @round (F, op (inf (a), sup (b)), op (sup (a), inf (b)))
@@ -131,7 +131,7 @@ Implement the `div` function of the IEEE Std 1788-2015 (Table 9.1).
131
131
132
132
Note: the behavior of the division is flavor dependent for some edge cases.
133
133
"""
134
- function / (a:: F , b:: Real ) where {F<: Interval }
134
+ function / (a:: F , b:: T ) where {T <: NumTypes , F<: Interval{T} }
135
135
isempty (a) && return emptyinterval (T)
136
136
iszero (b) && return div_by_thin_zero (a)
137
137
@@ -142,9 +142,11 @@ function /(a::F, b::Real) where {F<:Interval}
142
142
end
143
143
end
144
144
145
+ / (a:: Interval{T} , b:: Real ) where {T<: NumTypes } = a / interval (T, b)
146
+
145
147
/ (a:: Real , b:: Interval ) = a * inv (b)
146
148
147
- function / (a:: F , b:: F ) where {T, F<: Interval{T} }
149
+ function / (a:: F , b:: F ) where {T<: NumTypes , F<: Interval{T} }
148
150
(isempty (a) || isempty (b)) && return emptyinterval (F)
149
151
isthinzero (b) && return div_by_thin_zero (a)
150
152
@@ -162,13 +164,13 @@ function /(a::F, b::F) where {T, F<:Interval{T}}
162
164
isthinzero (a) && return a
163
165
164
166
if iszero (inf (b))
165
- inf (a) >= zero (T) && return @round (F, inf (a)/ sup (b), T ( Inf ))
166
- sup (a) <= zero (T) && return @round (F, T ( - Inf ), sup (a)/ sup (b))
167
+ inf (a) >= zero (T) && return @round (F, inf (a)/ sup (b), typemax (T ))
168
+ sup (a) <= zero (T) && return @round (F, typemin (T ), sup (a)/ sup (b))
167
169
return entireinterval (F)
168
170
169
171
elseif iszero (sup (b))
170
- inf (a) >= zero (T) && return @round (F, T ( - Inf ), inf (a)/ inf (b))
171
- sup (a) <= zero (T) && return @round (F, sup (a)/ inf (b), T ( Inf ))
172
+ inf (a) >= zero (T) && return @round (F, typemin (T ), inf (a)/ inf (b))
173
+ sup (a) <= zero (T) && return @round (F, sup (a)/ inf (b), typemax (T ))
172
174
return entireinterval (F)
173
175
174
176
else
@@ -186,12 +188,12 @@ Implement the `recip` function of the IEEE Std 1788-2015 (Table 9.1).
186
188
187
189
Note: the behavior of this function is flavor dependent for some edge cases.
188
190
"""
189
- function inv (a:: F ) where {T, F<: Interval{T} }
191
+ function inv (a:: F ) where {T<: NumTypes , F<: Interval{T} }
190
192
isempty (a) && return emptyinterval (F)
191
193
192
194
if zero (T) ∈ a
193
- inf (a) < zero (T) == sup (a) && return @round (F, T ( - Inf ), inv (inf (a)))
194
- inf (a) == zero (T) < sup (a) && return @round (F, inv (sup (a)), T ( Inf ))
195
+ inf (a) < zero (T) == sup (a) && return @round (F, typemin (T ), inv (inf (a)))
196
+ inf (a) == zero (T) < sup (a) && return @round (F, inv (sup (a)), typemax (T ))
195
197
inf (a) < zero (T) < sup (a) && return entireinterval (F)
196
198
isthinzero (a) && return div_by_thin_zero (one (F))
197
199
end
@@ -217,7 +219,7 @@ Fused multiply-add.
217
219
218
220
Implement the `fma` function of the IEEE Std 1788-2015 (Table 9.1).
219
221
"""
220
- function fma (a:: F , b:: F , c:: F ) where {T, F<: Interval{T} }
222
+ function fma (a:: F , b:: F , c:: F ) where {T<: NumTypes , F<: Interval{T} }
221
223
(isempty (a) || isempty (b) || isempty (c)) && return emptyinterval (F)
222
224
223
225
if isentire (a)
0 commit comments