@@ -37,26 +37,26 @@ abs(x::Fixed{T,f}) where {T,f} = Fixed{T,f}(abs(x.i),0)
3737# with truncation:
3838# *{f}(x::Fixed32{f}, y::Fixed32{f}) = Fixed32{f}(Base.widemul(x.i,y.i)>>f,0)
3939# 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 )
4141
4242/ (x:: Fixed{T,f} , y:: Fixed{T,f} ) where {T,f} = Fixed {T,f} (div (convert (widen (T), x. i) << f, y. i), 0 )
4343
4444
4545# # conversions and promotions
4646convert (:: 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 )
4848convert (:: Type{Fixed{T,f}} , x:: Rational ) where {T,f} = Fixed {T,f} (x. num)/ Fixed {T,f} (x. den)
4949
5050rem (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 )
5252
5353# convert{T,f}(::Type{AbstractFloat}, x::Fixed{T,f}) = convert(floattype(x), x)
5454float (x:: Fixed ) = convert (floattype (x), x)
5555
5656convert (:: 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)
5858convert (:: 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)
6060
6161convert (:: Type{Bool} , x:: Fixed{T,f} ) where {T,f} = x. i!= 0
6262function 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}
6969end
7070
7171convert (:: 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))
7373
7474promote_rule (ft:: Type{Fixed{T,f}} , :: Type{TI} ) where {T,f,TI <: Integer } = Fixed{T,f}
7575promote_rule (:: Type{Fixed{T,f}} , :: Type{TF} ) where {T,f,TF <: AbstractFloat } = TF
0 commit comments