@@ -37,26 +37,26 @@ abs(x::Fixed{T,f}) where {T,f} = Fixed{T,f}(abs(x.i),0)
37
37
# with truncation:
38
38
# *{f}(x::Fixed32{f}, y::Fixed32{f}) = Fixed32{f}(Base.widemul(x.i,y.i)>>f,0)
39
39
# with rounding up:
40
- * (x:: Fixed{T,f} , y:: Fixed{T,f} ) where {T,f} = Fixed {T,f} ((Base. widemul (x. i,y. i) + (convert (widen (T), 1 ) << (f- 1 ) ))>> f,0 )
40
+ * (x:: Fixed{T,f} , y:: Fixed{T,f} ) where {T,f} = Fixed {T,f} ((Base. widemul (x. i,y. i) + (one (widen (T)) << (f- 1 )))>> f,0 )
41
41
42
42
/ (x:: Fixed{T,f} , y:: Fixed{T,f} ) where {T,f} = Fixed {T,f} (div (convert (widen (T), x. i) << f, y. i), 0 )
43
43
44
44
45
45
# # conversions and promotions
46
46
convert (:: Type{Fixed{T,f}} , x:: Integer ) where {T,f} = Fixed {T,f} (round (T, convert (widen1 (T),x)<< f),0 )
47
- convert (:: Type{Fixed{T,f}} , x:: AbstractFloat ) where {T,f} = Fixed {T,f} (round (T, trunc (widen1 (T),x)<< f + rem (x,1 )* (1 << f)),0 )
47
+ convert (:: Type{Fixed{T,f}} , x:: AbstractFloat ) where {T,f} = Fixed {T,f} (round (T, trunc (widen1 (T),x)<< f + rem (x,1 )* (one ( widen1 (T)) << f)),0 )
48
48
convert (:: Type{Fixed{T,f}} , x:: Rational ) where {T,f} = Fixed {T,f} (x. num)/ Fixed {T,f} (x. den)
49
49
50
50
rem (x:: Integer , :: Type{Fixed{T,f}} ) where {T,f} = Fixed {T,f} (rem (x,T)<< f,0 )
51
- rem (x:: Real , :: Type{Fixed{T,f}} ) where {T,f} = Fixed {T,f} (rem (Integer (trunc (x)),T)<< f + rem (Integer (round (rem (x,1 )* (1 << f))),T),0 )
51
+ rem (x:: Real , :: Type{Fixed{T,f}} ) where {T,f} = Fixed {T,f} (rem (Integer (trunc (x)),T)<< f + rem (Integer (round (rem (x,1 )* (one ( widen1 (T)) << f))),T),0 )
52
52
53
53
# convert{T,f}(::Type{AbstractFloat}, x::Fixed{T,f}) = convert(floattype(x), x)
54
54
float (x:: Fixed ) = convert (floattype (x), x)
55
55
56
56
convert (:: Type{BigFloat} , x:: Fixed{T,f} ) where {T,f} =
57
- convert (BigFloat,x. i>> f) + convert (BigFloat,x. i& (1 << f - 1 ))/ convert (BigFloat,1 << f)
57
+ convert (BigFloat,x. i>> f) + convert (BigFloat,x. i& (one ( widen1 (T)) << f - 1 ))/ convert (BigFloat,one ( widen1 (T)) << f)
58
58
convert (:: Type{TF} , x:: Fixed{T,f} ) where {TF <: AbstractFloat ,T,f} =
59
- convert (TF,x. i>> f) + convert (TF,x. i& (1 << f - 1 ))/ convert (TF,1 << f)
59
+ convert (TF,x. i>> f) + convert (TF,x. i& (one ( widen1 (T)) << f - 1 ))/ convert (TF,one ( widen1 (T)) << f)
60
60
61
61
convert (:: Type{Bool} , x:: Fixed{T,f} ) where {T,f} = x. i!= 0
62
62
function convert (:: Type{Integer} , x:: Fixed{T,f} ) where {T,f}
@@ -69,7 +69,7 @@ function convert(::Type{TI}, x::Fixed{T,f}) where {TI <: Integer,T,f}
69
69
end
70
70
71
71
convert (:: Type{TR} , x:: Fixed{T,f} ) where {TR <: Rational ,T,f} =
72
- convert (TR, x. i>> f + (x. i& (1 << f- 1 ))// (1 << f))
72
+ convert (TR, x. i>> f + (x. i& (1 << f- 1 ))// (one ( widen1 (T)) << f))
73
73
74
74
promote_rule (ft:: Type{Fixed{T,f}} , :: Type{TI} ) where {T,f,TI <: Integer } = Fixed{T,f}
75
75
promote_rule (:: Type{Fixed{T,f}} , :: Type{TF} ) where {T,f,TF <: AbstractFloat } = TF
0 commit comments