@@ -8,7 +8,7 @@ import Base: ==, <, <=, -, +, *, /, ~,
88 convert, promote_rule, show, showcompact, isinteger, abs, decompose,
99 isnan, isinf, isfinite,
1010 zero, one, typemin, typemax, realmin, realmax, eps, sizeof, reinterpret,
11- trunc, round, floor, ceil, bswap,
11+ float, trunc, round, floor, ceil, bswap,
1212 div, fld, rem, mod, mod1, rem1, fld1, min, max, minmax,
1313 start, next, done, r_promote, reducedim_init
1414
@@ -55,6 +55,7 @@ reinterpret(x::FixedPoint) = x.i
5555# predicates
5656isinteger {T,f} (x:: FixedPoint{T,f} ) = (x. i& (1 << f- 1 )) == 0
5757
58+ # traits
5859typemax {T<: FixedPoint} (:: Type{T} ) = T (typemax (rawtype (T)), 0 )
5960typemin {T<: FixedPoint} (:: Type{T} ) = T (typemin (rawtype (T)), 0 )
6061realmin {T<: FixedPoint} (:: Type{T} ) = typemin (T)
@@ -70,10 +71,25 @@ widen1(::Type{Int64}) = Int128
7071widen1 (:: Type{UInt64} ) = UInt128
7172widen1 (x:: Integer ) = x % widen1 (typeof (x))
7273
74+ if VERSION <= v " 0.5.0-dev+755"
75+ @generated function floattype {T,f} (:: Type{FixedPoint{T,f}} )
76+ f> 22 ? :(Float64) : :(Float32)
77+ end
78+ else
79+ @pure function floattype {T,f} (:: Type{FixedPoint{T,f}} )
80+ f> 22 ? Float64 : Float32
81+ end
82+ end
83+ floattype (x:: FixedPoint ) = floattype (supertype (typeof (x)))
84+
85+
7386include (" fixed.jl" )
7487include (" ufixed.jl" )
7588include (" deprecations.jl" )
7689
90+ eps {T<:FixedPoint} (:: Type{T} ) = T (one (rawtype (T)),0 )
91+ eps {T<:FixedPoint} (:: T ) = eps (T)
92+ sizeof {T<:FixedPoint} (:: Type{T} ) = sizeof (rawtype (T))
7793
7894# Promotions for reductions
7995const Treduce = Float64
@@ -115,7 +131,7 @@ function show{T,f}(io::IO, x::FixedPoint{T,f})
115131 print (io, " )" )
116132end
117133const _log2_10 = 3.321928094887362
118- showcompact {T,f} (io:: IO , x:: FixedPoint{T,f} ) = show (io, round (convert (Float64, x), ceil (Int,f/ _log2_10)))
134+ showcompact {T,f} (io:: IO , x:: FixedPoint{T,f} ) = show (io, round (float ( x), ceil (Int,f/ _log2_10)))
119135
120136@noinline function throw_converterror {T<:FixedPoint} (:: Type{T} , x)
121137 n = 2 ^ (8 * sizeof (T))
0 commit comments