Skip to content

Commit f226e62

Browse files
committed
Deprecate UFixed8 and friends in favor of N0f8 and friends
1 parent 123f990 commit f226e62

File tree

5 files changed

+116
-131
lines changed

5 files changed

+116
-131
lines changed

src/FixedPointNumbers.jl

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,11 @@ using Compat
2727
abstract 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-
4530
export
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,
@@ -66,6 +43,7 @@ export
6643
scaledual
6744

6845
reinterpret(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+
119114
include("fixed.jl")
120115
include("ufixed.jl")
121116
include("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-
149136
for f in (:div, :fld, :fld1)
150137
@eval begin
151138
$f{T<:FixedPoint}(x::T, y::T) = $f(reinterpret(x),reinterpret(y))

src/deprecations.jl

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
import Base.@deprecate_binding
22

3+
@deprecate_binding Fixed16 Q15f16
4+
@deprecate_binding UFixed8 N0f8
5+
@deprecate_binding UFixed10 N6f10
6+
@deprecate_binding UFixed12 N4f12
7+
@deprecate_binding UFixed14 N2f14
8+
@deprecate_binding UFixed16 N0f16
9+
310
@deprecate_binding UfixedBase UFixed
411
@deprecate_binding UfixedConstructor UFixedConstructor
512
@deprecate_binding Ufixed UFixed
6-
@deprecate_binding Ufixed8 UFixed8
7-
@deprecate_binding Ufixed10 UFixed10
8-
@deprecate_binding Ufixed12 UFixed12
9-
@deprecate_binding Ufixed14 UFixed14
10-
@deprecate_binding Ufixed16 UFixed16
13+
@deprecate_binding Ufixed8 N0f8
14+
@deprecate_binding Ufixed10 N6f10
15+
@deprecate_binding Ufixed12 N4f12
16+
@deprecate_binding Ufixed14 N2f14
17+
@deprecate_binding Ufixed16 N0f16
18+
19+
@deprecate_binding Fixed32 Q15f16
20+
21+
const UF = (N0f8, N6f10, N4f12, N2f14, N0f16)
1122

12-
@deprecate_binding Fixed32 Fixed16
1323
@deprecate Fixed(x::Real) convert(Fixed{Int32, 16}, x)
1424

15-
@deprecate ufixed8(x) UFixed8(x)
16-
@deprecate ufixed10(x) UFixed10(x)
17-
@deprecate ufixed12(x) UFixed12(x)
18-
@deprecate ufixed14(x) UFixed14(x)
19-
@deprecate ufixed16(x) UFixed16(x)
25+
@deprecate ufixed8(x) N0f8(x)
26+
@deprecate ufixed10(x) N6f10(x)
27+
@deprecate ufixed12(x) N4f12(x)
28+
@deprecate ufixed14(x) N2f14(x)
29+
@deprecate ufixed16(x) N0f16(x)
2030

2131
Compat.@dep_vectorize_1arg Real ufixed8
2232
Compat.@dep_vectorize_1arg Real ufixed10

src/fixed.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ for T in (Int8, Int16, Int32, Int64)
2727
end
2828
end
2929

30-
# ASCII typealiases
31-
typealias Fixed16 Fixed{Int32,16}
30+
reinterpret{T<:Signed, f}(::Type{Fixed{T,f}}, x::T) = Fixed{T,f}(x, 0)
3231

3332
# basic operators
3433
-{T,f}(x::Fixed{T,f}) = Fixed{T,f}(-x.i,0)

src/ufixed.jl

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# UFixed{T,f} maps UInts from 0 to 2^f-1 to the range [0.0, 1.0]
2-
# For example, a UFixed8 maps 0x00 to 0.0 and 0xff to 1.0
2+
# For example, UFixed{UInt8,8} == N0f8 maps 0x00 to 0.0 and 0xff to 1.0
33

44
immutable UFixed{T<:Unsigned,f} <: FixedPoint{T,f}
55
i::T
@@ -25,17 +25,6 @@ for T in (UInt8, UInt16, UInt32, UInt64)
2525
end
2626
end
2727

28-
# ASCII typealiases
29-
typealias U8 UFixed{UInt8,8}
30-
typealias UFixed8 UFixed{UInt8,8}
31-
typealias UFixed10 UFixed{UInt16,10}
32-
typealias UFixed12 UFixed{UInt16,12}
33-
typealias UFixed14 UFixed{UInt16,14}
34-
typealias UFixed16 UFixed{UInt16,16}
35-
typealias U16 UFixed{UInt16,16}
36-
37-
const UF = (UFixed8, UFixed10, UFixed12, UFixed14, UFixed16)
38-
3928
reinterpret{T<:Unsigned, f}(::Type{UFixed{T,f}}, x::T) = UFixed{T,f}(x, 0)
4029

4130
## The next lines mimic the floating-point literal syntax "3.2f0"
@@ -65,7 +54,7 @@ function convert{T,T2,f}(::Type{UFixed{T,f}}, x::UFixed{T2})
6554
(0 <= y) & (y <= typemax(T)) || throw_converterror(U, x)
6655
reinterpret(U, _unsafe_trunc(T, y))
6756
end
68-
convert(::Type{UFixed16}, x::UFixed8) = reinterpret(UFixed16, convert(UInt16, 0x0101*reinterpret(x)))
57+
convert(::Type{N0f16}, x::N0f8) = reinterpret(N0f16, convert(UInt16, 0x0101*reinterpret(x)))
6958
convert{U<:UFixed}(::Type{U}, x::Real) = _convert(U, rawtype(U), x)
7059
function _convert{U<:UFixed,T}(::Type{U}, ::Type{T}, x)
7160
y = round(widen1(rawone(U))*x)

0 commit comments

Comments
 (0)