1
- # UfixedBase{T,f} maps Uints from 0 to 2^f-1 to the range [0.0, 1.0]
1
+ # UfixedBase{T,f} maps UInts from 0 to 2^f-1 to the range [0.0, 1.0]
2
2
# For example, a Ufixed8 maps 0x00 to 0.0 and 0xff to 1.0
3
3
4
4
immutable UfixedBase{T<: Unsigned ,f} <: Ufixed
@@ -8,31 +8,31 @@ immutable UfixedBase{T<:Unsigned,f} <: Ufixed
8
8
UfixedBase (x) = convert (UfixedBase{T,f}, x)
9
9
end
10
10
11
- typealias Ufixed8 UfixedBase{Uint8 ,8 }
12
- typealias Ufixed10 UfixedBase{Uint16 ,10 }
13
- typealias Ufixed12 UfixedBase{Uint16 ,12 }
14
- typealias Ufixed14 UfixedBase{Uint16 ,14 }
15
- typealias Ufixed16 UfixedBase{Uint16 ,16 }
11
+ typealias Ufixed8 UfixedBase{UInt8 ,8 }
12
+ typealias Ufixed10 UfixedBase{UInt16 ,10 }
13
+ typealias Ufixed12 UfixedBase{UInt16 ,12 }
14
+ typealias Ufixed14 UfixedBase{UInt16 ,14 }
15
+ typealias Ufixed16 UfixedBase{UInt16 ,16 }
16
16
17
17
const UF = (Ufixed8, Ufixed10, Ufixed12, Ufixed14, Ufixed16)
18
18
19
19
rawtype {T,f} (:: Type{UfixedBase{T,f}} ) = T
20
20
nbitsfrac {T,f} (:: Type{UfixedBase{T,f}} ) = f
21
21
22
- reinterpret (:: Type{Ufixed8} , x:: Uint8 ) = UfixedBase {Uint8 ,8} (x,0 )
22
+ reinterpret (:: Type{Ufixed8} , x:: UInt8 ) = UfixedBase {UInt8 ,8} (x,0 )
23
23
for (T,f) in ((Ufixed10,10 ),(Ufixed12,12 ),(Ufixed14,14 ),(Ufixed16,16 ))
24
- @eval reinterpret (:: Type{$T} , x:: Uint16 ) = UfixedBase {Uint16 ,$f} (x, 0 )
24
+ @eval reinterpret (:: Type{$T} , x:: UInt16 ) = UfixedBase {UInt16 ,$f} (x, 0 )
25
25
end
26
26
27
27
28
28
# The next lines mimic the floating-point literal syntax "3.2f0"
29
29
immutable UfixedConstructor{T,f} end
30
30
* {T,f}(n:: Integer , :: UfixedConstructor{T,f} ) = UfixedBase {T,f} (n,0 )
31
- const uf8 = UfixedConstructor {Uint8 ,8} ()
32
- const uf10 = UfixedConstructor {Uint16 ,10} ()
33
- const uf12 = UfixedConstructor {Uint16 ,12} ()
34
- const uf14 = UfixedConstructor {Uint16 ,14} ()
35
- const uf16 = UfixedConstructor {Uint16 ,16} ()
31
+ const uf8 = UfixedConstructor {UInt8 ,8} ()
32
+ const uf10 = UfixedConstructor {UInt16 ,10} ()
33
+ const uf12 = UfixedConstructor {UInt16 ,12} ()
34
+ const uf14 = UfixedConstructor {UInt16 ,14} ()
35
+ const uf16 = UfixedConstructor {UInt16 ,16} ()
36
36
37
37
zero {T,f} (:: Type{UfixedBase{T,f}} ) = UfixedBase {T,f} (zero (T),0 )
38
38
for T in UF
@@ -48,7 +48,7 @@ rawone(v) = reinterpret(one(v))
48
48
# Conversions
49
49
convert {T<:Ufixed} (:: Type{T} , x:: T ) = x
50
50
convert {T1<:Ufixed} (:: Type{T1} , x:: Ufixed ) = reinterpret (T1, round (rawtype (T1), (rawone (T1)/ rawone (x))* reinterpret (x)))
51
- convert (:: Type{Ufixed16} , x:: Ufixed8 ) = reinterpret (Ufixed16, convert (Uint16 , 0x0101 * reinterpret (x)))
51
+ convert (:: Type{Ufixed16} , x:: Ufixed8 ) = reinterpret (Ufixed16, convert (UInt16 , 0x0101 * reinterpret (x)))
52
52
convert {T<:Ufixed} (:: Type{T} , x:: Real ) = T (round (rawtype (T), rawone (T)* x),0 )
53
53
54
54
ufixed8 (x) = convert (Ufixed8, x)
@@ -65,7 +65,7 @@ ufixed16(x) = convert(Ufixed16, x)
65
65
66
66
67
67
convert (:: Type{BigFloat} , x:: Ufixed ) = reinterpret (x)* (1 / BigFloat (rawone (x)))
68
- convert {T<:FloatingPoint } (:: Type{T} , x:: Ufixed ) = reinterpret (x)* (1 / convert (T, rawone (x)))
68
+ convert {T<:AbstractFloat } (:: Type{T} , x:: Ufixed ) = reinterpret (x)* (1 / convert (T, rawone (x)))
69
69
convert (:: Type{Bool} , x:: Ufixed ) = x == zero (x) ? false : true
70
70
convert {T<:Integer} (:: Type{T} , x:: Ufixed ) = convert (T, x* (1 / one (T)))
71
71
convert {Ti<:Integer} (:: Type{Rational{Ti}} , x:: Ufixed ) = convert (Ti, reinterpret (x))// convert (Ti, rawone (x))
@@ -119,7 +119,7 @@ isfinite(x::Ufixed) = true
119
119
isnan (x:: Ufixed ) = false
120
120
isinf (x:: Ufixed ) = false
121
121
122
- bswap {f} (x:: UfixedBase{Uint8 ,f} ) = x
122
+ bswap {f} (x:: UfixedBase{UInt8 ,f} ) = x
123
123
bswap (x:: Ufixed ) = typeof (x)(bswap (reinterpret (x)),0 )
124
124
125
125
for f in (:div , :fld , :rem , :mod , :mod1 , :rem1 , :fld1 , :min , :max )
@@ -157,7 +157,7 @@ for T in UF
157
157
promote_rule (:: Type{$T} , :: Type{Float64} ) = Float64
158
158
promote_rule {TR<:Rational} (:: Type{$T} , :: Type{TR} ) = TR
159
159
end
160
- for Ti in (Int8, Uint8 , Int16, Uint16 , Int32, Uint32 , Int64, Uint64 )
160
+ for Ti in (Int8, UInt8 , Int16, UInt16 , Int32, UInt32 , Int64, UInt64 )
161
161
Tp = eps (convert (Float32, typemax (Ti))) > eps (T) ? Float64 : Float32
162
162
@eval begin
163
163
promote_rule (:: Type{$T} , :: Type{$Ti} ) = $ Tp
0 commit comments