@@ -27,34 +27,11 @@ using Compat
2727abstract FixedPoint{T <: Integer , f} <: Real
2828
2929
30- # Printing. These are used to generate type-symbols, so we need them early.
31- function showtype {X<:FixedPoint} (io:: IO , :: Type{X} )
32- print (io, typechar (X))
33- f = nbitsfrac (X)
34- m = sizeof (X)* 8 - f- signbits (X)
35- print (io, m, ' f' , f)
36- io
37- end
38- function show {T,f} (io:: IO , x:: FixedPoint{T,f} )
39- showcompact (io, x)
40- showtype (io, typeof (x))
41- end
42- const _log2_10 = 3.321928094887362
43- showcompact {T,f} (io:: IO , x:: FixedPoint{T,f} ) = show (io, round (convert (Float64,x), ceil (Int,f/ _log2_10)))
44-
4530export
4631 FixedPoint,
4732 Fixed,
4833 UFixed,
4934# "special" typealiases
50- Fixed16,
51- UFixed8,
52- U8,
53- UFixed10,
54- UFixed12,
55- UFixed14,
56- UFixed16,
57- U16,
5835 # Q and U typealiases are exported in separate source files
5936# literal constructor constants
6037 uf8,
6643 scaledual
6744
6845reinterpret (x:: FixedPoint ) = x. i
46+ reinterpret {T,f} (:: Type{T} , x:: FixedPoint{T,f} ) = x. i
6947
7048# construction using the (approximate) intended value, i.e., N0f8
7149* {X<: FixedPoint }(x:: Real , :: Type{X} ) = X (x)
@@ -116,6 +94,23 @@ floattype(x::FixedPoint) = floattype(supertype(typeof(x)))
11694# This IOBuffer is used during module definition to generate typealias names
11795_iotypealias = IOBuffer ()
11896
97+ # Printing. These are used to generate type-symbols, so we need them
98+ # before we include any files.
99+ function showtype {X<:FixedPoint} (io:: IO , :: Type{X} )
100+ print (io, typechar (X))
101+ f = nbitsfrac (X)
102+ m = sizeof (X)* 8 - f- signbits (X)
103+ print (io, m, ' f' , f)
104+ io
105+ end
106+ function show {T,f} (io:: IO , x:: FixedPoint{T,f} )
107+ showcompact (io, x)
108+ showtype (io, typeof (x))
109+ end
110+ const _log2_10 = 3.321928094887362
111+ showcompact {T,f} (io:: IO , x:: FixedPoint{T,f} ) = show (io, round (convert (Float64,x), ceil (Int,f/ _log2_10)))
112+
113+
119114include (" fixed.jl" )
120115include (" ufixed.jl" )
121116include (" deprecations.jl" )
@@ -138,14 +133,6 @@ reducedim_init{T<:FixedPoint}(f::typeof(@functorize(identity)),
138133 A:: AbstractArray{T} , region) =
139134 reducedim_initarray (A, region, one (Treduce))
140135
141- # TODO : rewrite this by @generated
142- for T in tuple (Fixed16, UF... )
143- R = rawtype (T)
144- @eval begin
145- reinterpret (:: Type{$R} , x:: $T ) = x. i
146- end
147- end
148-
149136for f in (:div , :fld , :fld1 )
150137 @eval begin
151138 $ f {T<:FixedPoint} (x:: T , y:: T ) = $ f (reinterpret (x),reinterpret (y))
0 commit comments