230
230
_apply_exact_float {T} (f, :: Type{T} , x:: Real , i:: Integer ) = f (T, x, i)
231
231
232
232
for fn in [:trunc , :floor , :ceil ]
233
- @eval $ fn {TI <: Integer} (:: Type{TI} , x:: FD ):: TI = $ fn (x)
233
+ @eval ( $ fn {TI <: Integer} (:: Type{TI} , x:: FD ):: TI ) = $ fn (x)
234
234
235
235
# round/trunc/ceil/flooring to FD; generic
236
236
@eval function $fn {T, f} (:: Type{FD{T, f}} , x:: Real )
@@ -241,8 +241,8 @@ for fn in [:trunc, :floor, :ceil]
241
241
reinterpret (FD{T, f}, val)
242
242
end
243
243
end
244
- function round {TI <: Integer} (:: Type{TI} , x:: FD , :: RoundingMode{:Nearest} = RoundNearest):: TI
245
- round (x)
244
+ function round {TI <: Integer} (:: Type{TI} , x:: FD , :: RoundingMode{:Nearest} = RoundNearest)
245
+ convert (TI, round (x)) :: TI
246
246
end
247
247
function round {T, f} (:: Type{FD{T, f}} , x:: Real , :: RoundingMode{:Nearest} = RoundNearest)
248
248
reinterpret (FD{T, f}, round (T, x * coefficient (FD{T, f})))
260
260
261
261
convert {T <: FD} (:: Type{T} , x:: AbstractFloat ) = round (T, x)
262
262
263
- function convert {T, f} (:: Type{FD{T, f}} , x:: Rational ):: FD{T, f}
263
+ function convert {T, f} (:: Type{FD{T, f}} , x:: Rational )
264
264
powt = coefficient (FD{T, f})
265
- reinterpret (FD{T, f}, T (x * powt))
265
+ reinterpret (FD{T, f}, T (x * powt)):: FD{T, f}
266
266
end
267
267
268
268
function convert {T, f, U, g} (:: Type{FD{T, f}} , x:: FD{U, g} )
@@ -290,20 +290,22 @@ for divfn in [:div, :fld, :fld1]
290
290
end
291
291
292
292
convert (:: Type{AbstractFloat} , x:: FD ) = convert (floattype (typeof (x)), x)
293
- function convert {TF <: AbstractFloat, T, f} (:: Type{TF} , x:: FD{T, f} ):: TF
294
- x. i / coefficient (FD{T, f})
293
+ function convert {TF <: AbstractFloat, T, f} (:: Type{TF} , x:: FD{T, f} )
294
+ convert (TF, x. i / coefficient (FD{T, f})) :: TF
295
295
end
296
296
297
- function convert {TF <: BigFloat, T, f} (:: Type{TF} , x:: FD{T, f} ):: TF
298
- BigInt (x. i) / BigInt (coefficient (FD{T, f}))
297
+ function convert {TF <: BigFloat, T, f} (:: Type{TF} , x:: FD{T, f} )
298
+ convert (TF, BigInt (x. i) / BigInt (coefficient (FD{T, f}))) :: TF
299
299
end
300
300
301
- function convert {TI <: Integer, T, f} (:: Type{TI} , x:: FD{T, f} ):: TI
301
+ function convert {TI <: Integer, T, f} (:: Type{TI} , x:: FD{T, f} )
302
302
isinteger (x) || throw (InexactError (:convert , TI, x))
303
- div (x. i, coefficient (FD{T, f}))
303
+ convert (TI, div (x. i, coefficient (FD{T, f}))) :: TI
304
304
end
305
305
306
- convert {TR <: Rational, T, f} (:: Type{TR} , x:: FD{T, f} ):: TR = x. i // coefficient (FD{T, f})
306
+ function convert {TR <: Rational, T, f} (:: Type{TR} , x:: FD{T, f} )
307
+ convert (TR, x. i // coefficient (FD{T, f})):: TR
308
+ end
307
309
308
310
promote_rule {T, f, TI <: Integer} (:: Type{FD{T, f}} , :: Type{TI} ) = FD{T, f}
309
311
promote_rule {T, f, TF <: AbstractFloat} (:: Type{FD{T, f}} , :: Type{TF} ) = TF
0 commit comments