@@ -32,23 +32,23 @@ struct IntervalRounding{T} end
32
32
# Functions that are the same for all rounding types:
33
33
@eval begin
34
34
# unary minus:
35
- - {T <: AbstractFloat } (a:: T , :: RoundingMode ) = - a # ignore rounding
35
+ - (a:: T , :: RoundingMode ) where {T <: AbstractFloat } = - a # ignore rounding
36
36
37
37
# zero:
38
- zero {T<:AbstractFloat} (a:: Interval{T} , :: RoundingMode ) = zero (T)
39
- zero {T<:AbstractFloat} (:: Type{T} , :: RoundingMode ) = zero (T)
38
+ zero (a:: Interval{T} , :: RoundingMode ) where {T <: AbstractFloat } = zero (T)
39
+ zero (:: Type{T} , :: RoundingMode ) where {T <: AbstractFloat } = zero (T)
40
40
41
41
convert (:: Type{BigFloat} , x, rounding_mode:: RoundingMode ) =
42
42
setrounding (BigFloat, rounding_mode) do
43
43
convert (BigFloat, x)
44
44
end
45
45
46
- parse {T} (:: Type{T} , x, rounding_mode:: RoundingMode ) = setrounding (T, rounding_mode) do
46
+ parse (:: Type{T} , x, rounding_mode:: RoundingMode ) where {T} = setrounding (T, rounding_mode) do
47
47
parse (T, x)
48
48
end
49
49
50
50
51
- sqrt {T<:Rational} (a:: T , rounding_mode:: RoundingMode ) = setrounding (float (T), rounding_mode) do
51
+ sqrt (a:: T , rounding_mode:: RoundingMode ) where {T <: Rational } = setrounding (float (T), rounding_mode) do
52
52
sqrt (float (a))
53
53
end
54
54
58
58
59
59
# no-ops for rational rounding:
60
60
for f in (:+ , :- , :* , :/ )
61
- @eval $ f {T<:Rational} (a:: T , b:: T , :: RoundingMode ) = $ f (a, b)
61
+ @eval $ f (a:: T , b:: T , :: RoundingMode ) where {T <: Rational } = $ f (a, b)
62
62
end
63
63
64
64
# error-free arithmetic:
@@ -114,68 +114,68 @@ for mode in (:Down, :Up)
114
114
# binary functions:
115
115
for f in (:+ , :- , :* , :/ , :atan2 )
116
116
117
- @eval function $f {T<:AbstractFloat} (:: IntervalRounding{:slow} ,
118
- a:: T , b:: T , $ mode1)
117
+ @eval function $f (:: IntervalRounding{:slow} ,
118
+ a:: T , b:: T , $ mode1) where T <: AbstractFloat
119
119
setrounding (T, $ mode2) do
120
120
$ f (a, b)
121
121
end
122
122
end
123
123
124
- @eval function $f {T<:AbstractFloat} (:: IntervalRounding{:tight} ,
125
- a:: T , b:: T , $ mode1)
124
+ @eval function $f (:: IntervalRounding{:tight} ,
125
+ a:: T , b:: T , $ mode1) where T <: AbstractFloat
126
126
setrounding (T, $ mode2) do
127
127
$ f (a, b)
128
128
end
129
129
end
130
130
131
- @eval $ f {T<:AbstractFloat} (:: IntervalRounding{:accurate} ,
132
- a:: T , b:: T , $ mode1) = $ directed ($ f (a, b))
131
+ @eval $ f (:: IntervalRounding{:accurate} ,
132
+ a:: T , b:: T , $ mode1) where {T <: AbstractFloat } = $ directed ($ f (a, b))
133
133
134
- @eval $ f {T<:AbstractFloat} (:: IntervalRounding{:none} ,
135
- a:: T , b:: T , $ mode1) = $ f (a, b)
134
+ @eval $ f (:: IntervalRounding{:none} ,
135
+ a:: T , b:: T , $ mode1) where {T <: AbstractFloat } = $ f (a, b)
136
136
137
137
end
138
138
139
139
140
140
# power:
141
141
142
- @eval function ^ {S <: Real } (:: IntervalRounding{:slow} ,
143
- a:: BigFloat , b:: S , $ mode1)
142
+ @eval function ^ (:: IntervalRounding{:slow} ,
143
+ a:: BigFloat , b:: S , $ mode1) where S <: Real
144
144
setrounding (BigFloat, $ mode2) do
145
145
^ (a, b)
146
146
end
147
147
end
148
148
149
149
# for correct rounding for Float64, must pass through BigFloat:
150
- @eval function ^ {S <: Real } (:: IntervalRounding{:slow} , a:: Float64 , b:: S , $ mode1)
150
+ @eval function ^ (:: IntervalRounding{:slow} , a:: Float64 , b:: S , $ mode1) where S <: Real
151
151
setprecision (BigFloat, 53 ) do
152
152
Float64 (^ (IntervalRounding{:slow }, BigFloat (a), b, $ mode2))
153
153
end
154
154
end
155
155
156
- @eval ^ {T <: AbstractFloat ,S <: Real } (:: IntervalRounding{:accurate} ,
157
- a:: T , b:: S , $ mode1) = $ directed (a^ b)
156
+ @eval ^ (:: IntervalRounding{:accurate} ,
157
+ a:: T , b:: S , $ mode1) where {T <: AbstractFloat ,S <: Real } = $ directed (a^ b)
158
158
159
- @eval ^ {T <: AbstractFloat ,S <: Real } (:: IntervalRounding{:none} ,
160
- a:: T , b:: S , $ mode1) = a^ b
159
+ @eval ^ (:: IntervalRounding{:none} ,
160
+ a:: T , b:: S , $ mode1) where {T <: AbstractFloat ,S <: Real } = a^ b
161
161
162
162
163
163
# functions not in CRlibm:
164
164
for f in (:sqrt , :inv , :tanh , :asinh , :acosh , :atanh )
165
165
166
- @eval function $f {T<:AbstractFloat} (:: IntervalRounding{:slow} ,
167
- a:: T , $ mode1)
166
+ @eval function $f (:: IntervalRounding{:slow} ,
167
+ a:: T , $ mode1) where T <: AbstractFloat
168
168
setrounding (T, $ mode2) do
169
169
$ f (a)
170
170
end
171
171
end
172
172
173
173
174
- @eval $ f {T<:AbstractFloat} (:: IntervalRounding{:accurate} ,
175
- a:: T , $ mode1) = $ directed ($ f (a))
174
+ @eval $ f (:: IntervalRounding{:accurate} ,
175
+ a:: T , $ mode1) where {T <: AbstractFloat } = $ directed ($ f (a))
176
176
177
- @eval $ f {T<:AbstractFloat} (:: IntervalRounding{:none} ,
178
- a:: T , $ mode1) = $ f (a)
177
+ @eval $ f (:: IntervalRounding{:none} ,
178
+ a:: T , $ mode1) where {T <: AbstractFloat } = $ f (a)
179
179
180
180
181
181
end
@@ -184,14 +184,14 @@ for mode in (:Down, :Up)
184
184
# Functions defined in CRlibm
185
185
186
186
for f in CRlibm. functions
187
- @eval $ f {T<:AbstractFloat} (:: IntervalRounding{:slow} ,
188
- a:: T , $ mode1) = CRlibm.$ f (a, $ mode2)
187
+ @eval $ f (:: IntervalRounding{:slow} ,
188
+ a:: T , $ mode1) where {T <: AbstractFloat } = CRlibm.$ f (a, $ mode2)
189
189
190
- @eval $ f {T<:AbstractFloat} (:: IntervalRounding{:accurate} ,
191
- a:: T , $ mode1) = $ directed ($ f (a))
190
+ @eval $ f (:: IntervalRounding{:accurate} ,
191
+ a:: T , $ mode1) where {T <: AbstractFloat } = $ directed ($ f (a))
192
192
193
- @eval $ f {T<:AbstractFloat} (:: IntervalRounding{:none} ,
194
- a:: T , $ mode1) = $ f (a)
193
+ @eval $ f (:: IntervalRounding{:none} ,
194
+ a:: T , $ mode1) where {T <: AbstractFloat } = $ f (a)
195
195
196
196
end
197
197
end
@@ -214,7 +214,7 @@ function _setrounding(::Type{Interval}, rounding_type::Symbol)
214
214
215
215
# binary functions:
216
216
for f in (:+ , :- , :* , :/ )
217
- @eval $ f {T<:AbstractFloat} (a:: T , b:: T , r:: RoundingMode ) = $ f ($ roundtype, a, b, r)
217
+ @eval $ f (a:: T , b:: T , r:: RoundingMode ) where {T <: AbstractFloat } = $ f ($ roundtype, a, b, r)
218
218
end
219
219
220
220
if rounding_type == :tight # for remaining functions, use CRlibm
@@ -223,16 +223,16 @@ function _setrounding(::Type{Interval}, rounding_type::Symbol)
223
223
224
224
for f in (:^ , :atan2 )
225
225
226
- @eval $ f {T<:AbstractFloat} (a:: T , b:: T , r:: RoundingMode ) = $ f ($ roundtype, a, b, r)
226
+ @eval $ f (a:: T , b:: T , r:: RoundingMode ) where {T <: AbstractFloat } = $ f ($ roundtype, a, b, r)
227
227
end
228
228
229
- @eval ^ {T <: AbstractFloat , S <: Real } (a:: T , b:: S , r:: RoundingMode ) = ^ ($ roundtype, promote (a, b)... , r)
229
+ @eval ^ (a:: T , b:: S , r:: RoundingMode ) where {T <: AbstractFloat , S <: Real } = ^ ($ roundtype, promote (a, b)... , r)
230
230
231
231
# unary functions:
232
232
for f in vcat (CRlibm. functions,
233
233
[:sqrt , :inv , :tanh , :asinh , :acosh , :atanh ])
234
234
235
- @eval $ f {T<:AbstractFloat} (a:: T , r:: RoundingMode ) = $ f ($ roundtype, a, r)
235
+ @eval $ f (a:: T , r:: RoundingMode ) where {T <: AbstractFloat } = $ f ($ roundtype, a, r)
236
236
237
237
@eval $ f (x:: Real , r:: RoundingMode ) = $ f (float (x), r)
238
238
0 commit comments