@@ -42,7 +42,7 @@ rawone(v) = reinterpret(one(v))
4242# Conversions
4343convert {T<:UFixed} (:: Type{T} , x:: T ) = x
4444convert {T1,T2,f} (:: Type{UFixed{T1,f}} , x:: UFixed{T2,f} ) = UFixed {T1,f} (convert (T1, x. i), 0 )
45- function convert {T,f} (:: Type{UFixed{T,f}} , x:: UFixed )
45+ function convert {T,T2, f} (:: Type{UFixed{T,f}} , x:: UFixed{T2} )
4646 U = UFixed{T,f}
4747 y = round ((rawone (U)/ rawone (x))* reinterpret (x))
4848 (0 <= y) & (y <= typemax (T)) || throw_converterror (U, x)
@@ -82,8 +82,14 @@ sizeof{T<:UFixed}(::Type{T}) = sizeof(rawtype(T))
8282abs (x:: UFixed ) = x
8383
8484# Arithmetic
85- @generated function floattype {U<:UFixed} (:: Type{U} )
86- eps (U) < eps (Float32) ? :(Float64) : :(Float32)
85+ if VERSION <= v " 0.5.0-dev+755"
86+ @generated function floattype {T,f} (:: Type{UFixed{T,f}} )
87+ f> 22 ? :(Float64) : :(Float32)
88+ end
89+ else
90+ @pure function floattype {T,f} (:: Type{UFixed{T,f}} )
91+ f> 22 ? Float64 : Float32
92+ end
8793end
8894
8995(- ){T<: UFixed }(x:: T ) = T (- reinterpret (x), 0 )
@@ -158,12 +164,10 @@ function decompose(x::UFixed)
158164end
159165
160166# Promotions
161- promote_rule {T<:UFixed} (:: Type{T} , :: Type{Float32} ) = Float32
162- promote_rule {T<:UFixed} (:: Type{T} , :: Type{Float64} ) = Float64
167+ promote_rule {T<:UFixed,Tf<:AbstractFloat} (:: Type{T} , :: Type{Tf} ) = promote_type (floattype (T), Tf)
163168promote_rule {T<:UFixed, R<:Rational} (:: Type{T} , :: Type{R} ) = R
164- @generated function promote_rule {T<:UFixed, Ti<:Union{Signed,Unsigned}} (:: Type{T} , :: Type{Ti} )
165- Tp = eps (convert (Float32, typemax (Ti))) > eps (T) ? Float64 : Float32
166- :( $ Tp )
169+ function promote_rule {T<:UFixed, Ti<:Union{Signed,Unsigned}} (:: Type{T} , :: Type{Ti} )
170+ floattype (T)
167171end
168172@generated function promote_rule {T1,T2,f1,f2} (:: Type{UFixed{T1,f1}} , :: Type{UFixed{T2,f2}} )
169173 f = max (f1, f2) # ensure we have enough precision
0 commit comments