Skip to content

Commit 07acd3f

Browse files
authored
Merge pull request #89 from JuliaMath/teh/parametric_depwarns
Fix package on 0.7
2 parents 2259a00 + 0418d38 commit 07acd3f

File tree

8 files changed

+120
-133
lines changed

8 files changed

+120
-133
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ notifications:
1010
script:
1111
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
1212
- julia -e 'Pkg.clone(pwd()); Pkg.build("FixedPointNumbers")'
13-
- julia -e 'if VERSION >= v"0.6.0-dev.565" Pkg.test("FixedPointNumbers"; coverage=true); else cd(Pkg.dir("FixedPointNumbers", "test")); include("runtests.jl"); end '
13+
- julia -e 'Pkg.test("FixedPointNumbers"; coverage=true)'
1414
after_success:
1515
# push coverage results to Codecov
16-
- julia -e 'if VERSION >= v"0.6.0-dev.565" cd(Pkg.dir("FixedPointNumbers")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder()); end'
16+
- julia -e 'cd(Pkg.dir("FixedPointNumbers")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.5
2-
Compat 0.17.0
1+
julia 0.6

src/FixedPointNumbers.jl

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ if isdefined(Base, :rem1)
1616
end
1717
using Base: @pure
1818

19-
using Compat
20-
2119
# T => BaseType
2220
# f => Number of Bytes reserved for fractional part
23-
@compat abstract type FixedPoint{T <: Integer, f} <: Real end
21+
abstract type FixedPoint{T <: Integer, f} <: Real end
2422

2523

2624
export
@@ -39,21 +37,21 @@ export
3937
scaledual
4038

4139
reinterpret(x::FixedPoint) = x.i
42-
reinterpret{T,f}(::Type{T}, x::FixedPoint{T,f}) = x.i
40+
reinterpret(::Type{T}, x::FixedPoint{T,f}) where {T,f} = x.i
4341

4442
# construction using the (approximate) intended value, i.e., N0f8
45-
*{X<:FixedPoint}(x::Real, ::Type{X}) = X(x)
43+
*(x::Real, ::Type{X}) where {X<:FixedPoint} = X(x)
4644

4745
# comparison
48-
=={T <: FixedPoint}(x::T, y::T) = x.i == y.i
49-
<{T <: FixedPoint}(x::T, y::T) = x.i < y.i
50-
<={T <: FixedPoint}(x::T, y::T) = x.i <= y.i
46+
==(x::T, y::T) where {T <: FixedPoint} = x.i == y.i
47+
<(x::T, y::T) where {T <: FixedPoint} = x.i < y.i
48+
<=(x::T, y::T) where {T <: FixedPoint} = x.i <= y.i
5149
"""
5250
isapprox(x::FixedPoint, y::FixedPoint; rtol=0, atol=max(eps(x), eps(y)))
5351
5452
For FixedPoint numbers, the default criterion is that `x` and `y` differ by no more than `eps`, the separation between adjacent fixed-point numbers.
5553
"""
56-
function isapprox{T<:FixedPoint}(x::T, y::T; rtol=0, atol=max(eps(x), eps(y)))
54+
function isapprox(x::T, y::T; rtol=0, atol=max(eps(x), eps(y))) where {T <: FixedPoint}
5755
maxdiff = T(atol+rtol*max(abs(x), abs(y)))
5856
rx, ry, rd = reinterpret(x), reinterpret(y), reinterpret(maxdiff)
5957
abs(signed(widen1(rx))-signed(widen1(ry))) <= rd
@@ -63,13 +61,13 @@ function isapprox(x::FixedPoint, y::FixedPoint; rtol=0, atol=max(eps(x), eps(y))
6361
end
6462

6563
# predicates
66-
isinteger{T,f}(x::FixedPoint{T,f}) = (x.i&(1<<f-1)) == 0
64+
isinteger(x::FixedPoint{T,f}) where {T,f} = (x.i&(1<<f-1)) == 0
6765

6866
# traits
69-
typemax{T<: FixedPoint}(::Type{T}) = T(typemax(rawtype(T)), 0)
70-
typemin{T<: FixedPoint}(::Type{T}) = T(typemin(rawtype(T)), 0)
71-
realmin{T<: FixedPoint}(::Type{T}) = eps(T)
72-
realmax{T<: FixedPoint}(::Type{T}) = typemax(T)
67+
typemax(::Type{T}) where {T <: FixedPoint} = T(typemax(rawtype(T)), 0)
68+
typemin(::Type{T}) where {T <: FixedPoint} = T(typemin(rawtype(T)), 0)
69+
realmin(::Type{T}) where {T <: FixedPoint} = eps(T)
70+
realmax(::Type{T}) where {T <: FixedPoint} = typemax(T)
7371

7472
widen1(::Type{Int8}) = Int16
7573
widen1(::Type{UInt8}) = UInt16
@@ -84,84 +82,84 @@ widen1(x::Integer) = x % widen1(typeof(x))
8482

8583
const ShortInts = Union{Int8,UInt8,Int16,UInt16}
8684

87-
floattype{T<:ShortInts,f}(::Type{FixedPoint{T,f}}) = Float32
88-
floattype{T<:Integer,f}(::Type{FixedPoint{T,f}}) = Float64
89-
floattype{F<:FixedPoint}(::Type{F}) = floattype(supertype(F))
85+
floattype(::Type{FixedPoint{T,f}}) where {T <: ShortInts,f} = Float32
86+
floattype(::Type{FixedPoint{T,f}}) where {T <: Integer,f} = Float64
87+
floattype(::Type{F}) where {F <: FixedPoint} = floattype(supertype(F))
9088
floattype(x::FixedPoint) = floattype(typeof(x))
9189

92-
nbitsfrac{T<:Integer,f}(::Type{FixedPoint{T,f}}) = f
93-
nbitsfrac{F<:FixedPoint}(::Type{F}) = nbitsfrac(supertype(F))
90+
nbitsfrac(::Type{FixedPoint{T,f}}) where {T <: Integer,f} = f
91+
nbitsfrac(::Type{F}) where {F <: FixedPoint} = nbitsfrac(supertype(F))
9492

95-
rawtype{T<:Integer,f}(::Type{FixedPoint{T,f}}) = T
96-
rawtype{F<:FixedPoint}(::Type{F}) = rawtype(supertype(F))
93+
rawtype(::Type{FixedPoint{T,f}}) where {T <: Integer,f} = T
94+
rawtype(::Type{F}) where {F <: FixedPoint} = rawtype(supertype(F))
9795
rawtype(x::FixedPoint) = rawtype(typeof(x))
9896

9997
# This IOBuffer is used during module definition to generate typealias names
10098
_iotypealias = IOBuffer()
10199

102100
# Printing. These are used to generate type-symbols, so we need them
103101
# before we include any files.
104-
function showtype{X<:FixedPoint}(io::IO, ::Type{X})
102+
function showtype(io::IO, ::Type{X}) where {X <: FixedPoint}
105103
print(io, typechar(X))
106104
f = nbitsfrac(X)
107105
m = sizeof(X)*8-f-signbits(X)
108106
print(io, m, 'f', f)
109107
io
110108
end
111-
function show{T,f}(io::IO, x::FixedPoint{T,f})
109+
function show(io::IO, x::FixedPoint{T,f}) where {T,f}
112110
showcompact(io, x)
113111
showtype(io, typeof(x))
114112
end
115113
const _log2_10 = 3.321928094887362
116-
showcompact{T,f}(io::IO, x::FixedPoint{T,f}) = show(io, round(convert(Float64,x), ceil(Int,f/_log2_10)))
114+
showcompact(io::IO, x::FixedPoint{T,f}) where {T,f} = show(io, round(convert(Float64,x), ceil(Int,f/_log2_10)))
117115

118116

119117
include("fixed.jl")
120118
include("normed.jl")
121119
include("deprecations.jl")
122120

123-
eps{T<:FixedPoint}(::Type{T}) = T(one(rawtype(T)),0)
124-
eps{T<:FixedPoint}(::T) = eps(T)
125-
sizeof{T<:FixedPoint}(::Type{T}) = sizeof(rawtype(T))
121+
eps(::Type{T}) where {T <: FixedPoint} = T(one(rawtype(T)),0)
122+
eps(::T) where {T <: FixedPoint} = eps(T)
123+
sizeof(::Type{T}) where {T <: FixedPoint} = sizeof(rawtype(T))
126124

127125
# Promotions for reductions
128126
const Treduce = Float64
129-
r_promote{T}(::typeof(+), x::FixedPoint{T}) = Treduce(x)
130-
r_promote{T}(::typeof(*), x::FixedPoint{T}) = Treduce(x)
127+
r_promote(::typeof(+), x::FixedPoint{T}) where {T} = Treduce(x)
128+
r_promote(::typeof(*), x::FixedPoint{T}) where {T} = Treduce(x)
131129

132-
reducedim_init{T<:FixedPoint}(f::typeof(identity),
130+
reducedim_init(f::typeof(identity),
133131
op::typeof(+),
134-
A::AbstractArray{T}, region) =
132+
A::AbstractArray{T}, region) where {T <: FixedPoint} =
135133
reducedim_initarray(A, region, zero(Treduce))
136-
reducedim_init{T<:FixedPoint}(f::typeof(identity),
134+
reducedim_init(f::typeof(identity),
137135
op::typeof(*),
138-
A::AbstractArray{T}, region) =
136+
A::AbstractArray{T}, region) where {T <: FixedPoint} =
139137
reducedim_initarray(A, region, one(Treduce))
140138

141139
for f in (:div, :fld, :fld1)
142140
@eval begin
143-
$f{T<:FixedPoint}(x::T, y::T) = $f(reinterpret(x),reinterpret(y))
141+
$f(x::T, y::T) where {T <: FixedPoint} = $f(reinterpret(x),reinterpret(y))
144142
end
145143
end
146144
for f in (:rem, :mod, :mod1, :rem1, :min, :max)
147145
if f === :rem1 && !isdefined(Base, :rem1)
148146
continue
149147
end
150148
@eval begin
151-
$f{T<:FixedPoint}(x::T, y::T) = T($f(reinterpret(x),reinterpret(y)),0)
149+
$f(x::T, y::T) where {T <: FixedPoint} = T($f(reinterpret(x),reinterpret(y)),0)
152150
end
153151
end
154152

155153
# When multiplying by a float, reduce two multiplies to one.
156154
# Particularly useful for arrays.
157155
scaledual(Tdual::Type, x) = one(Tdual), x
158-
scaledual{Tdual<:Number}(b::Tdual, x) = b, x
159-
scaledual{T<:FixedPoint}(Tdual::Type, x::Union{T,AbstractArray{T}}) =
156+
scaledual(b::Tdual, x) where {Tdual <: Number} = b, x
157+
scaledual(Tdual::Type, x::Union{T,AbstractArray{T}}) where {T <: FixedPoint} =
160158
convert(Tdual, 1/one(T)), reinterpret(rawtype(T), x)
161-
scaledual{Tdual<:Number, T<:FixedPoint}(b::Tdual, x::Union{T,AbstractArray{T}}) =
159+
scaledual(b::Tdual, x::Union{T,AbstractArray{T}}) where {Tdual <: Number,T <: FixedPoint} =
162160
convert(Tdual, b/one(T)), reinterpret(rawtype(T), x)
163161

164-
@noinline function throw_converterror{T<:FixedPoint}(::Type{T}, x)
162+
@noinline function throw_converterror(::Type{T}, x) where {T <: FixedPoint}
165163
n = 2^(8*sizeof(T))
166164
bitstring = sizeof(T) == 1 ? "an 8-bit" : "a $(8*sizeof(T))-bit"
167165
io = IOBuffer()
@@ -170,7 +168,7 @@ scaledual{Tdual<:Number, T<:FixedPoint}(b::Tdual, x::Union{T,AbstractArray{T}})
170168
throw(ArgumentError("$T is $bitstring type representing $n values from $Tmin to $Tmax; cannot represent $x"))
171169
end
172170

173-
rand{T<:FixedPoint}(::Type{T}) = reinterpret(T, rand(rawtype(T)))
174-
rand{T<:FixedPoint}(::Type{T}, sz::Dims) = reinterpret(T, rand(rawtype(T), sz))
171+
rand(::Type{T}) where {T <: FixedPoint} = reinterpret(T, rand(rawtype(T)))
172+
rand(::Type{T}, sz::Dims) where {T <: FixedPoint} = reinterpret(T, rand(rawtype(T), sz))
175173

176174
end # module

src/deprecations.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,10 @@ const UF = (N0f8, N6f10, N4f12, N2f14, N0f16)
2828
@deprecate ufixed14(x) N2f14(x)
2929
@deprecate ufixed16(x) N0f16(x)
3030

31-
Compat.@dep_vectorize_1arg Real ufixed8
32-
Compat.@dep_vectorize_1arg Real ufixed10
33-
Compat.@dep_vectorize_1arg Real ufixed12
34-
Compat.@dep_vectorize_1arg Real ufixed14
35-
Compat.@dep_vectorize_1arg Real ufixed16
36-
3731
## The next lines mimic the floating-point literal syntax "3.2f0"
3832
# construction using a UInt, i.e., 0xccuf8
3933
struct NormedConstructor{T,f} end
40-
function *{T,f}(n::Integer, ::NormedConstructor{T,f})
34+
function *(n::Integer, ::NormedConstructor{T,f}) where {T,f}
4135
i = 8*sizeof(T)-f
4236
io = IOBuffer()
4337
show(io, n)

src/fixed.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ struct Fixed{T <: Signed,f} <: FixedPoint{T, f}
44

55
# constructor for manipulating the representation;
66
# selected by passing an extra dummy argument
7-
(::Type{Fixed{T, f}}){T, f}(i::Integer, _) = new{T, f}(i % T)
8-
(::Type{Fixed{T, f}}){T, f}(x) = convert(Fixed{T,f}, x)
7+
(::Type{Fixed{T, f}})(i::Integer, _) where {T,f} = new{T, f}(i % T)
8+
(::Type{Fixed{T, f}})(x) where {T,f} = convert(Fixed{T,f}, x)
99
end
1010

11-
reinterpret{T<:Signed, f}(::Type{Fixed{T,f}}, x::T) = Fixed{T,f}(x, 0)
11+
reinterpret(::Type{Fixed{T,f}}, x::T) where {T <: Signed,f} = Fixed{T,f}(x, 0)
1212

13-
typechar{X<:Fixed}(::Type{X}) = 'Q'
14-
signbits{X<:Fixed}(::Type{X}) = 1
13+
typechar(::Type{X}) where {X <: Fixed} = 'Q'
14+
signbits(::Type{X}) where {X <: Fixed} = 1
1515

1616
for T in (Int8, Int16, Int32, Int64)
1717
for f in 0:sizeof(T)*8-1
@@ -24,52 +24,52 @@ for T in (Int8, Int16, Int32, Int64)
2424
end
2525

2626
# basic operators
27-
-{T,f}(x::Fixed{T,f}) = Fixed{T,f}(-x.i,0)
28-
abs{T,f}(x::Fixed{T,f}) = Fixed{T,f}(abs(x.i),0)
27+
-(x::Fixed{T,f}) where {T,f} = Fixed{T,f}(-x.i,0)
28+
abs(x::Fixed{T,f}) where {T,f} = Fixed{T,f}(abs(x.i),0)
2929

30-
+{T,f}(x::Fixed{T,f}, y::Fixed{T,f}) = Fixed{T,f}(x.i+y.i,0)
31-
-{T,f}(x::Fixed{T,f}, y::Fixed{T,f}) = Fixed{T,f}(x.i-y.i,0)
30+
+(x::Fixed{T,f}, y::Fixed{T,f}) where {T,f} = Fixed{T,f}(x.i+y.i,0)
31+
-(x::Fixed{T,f}, y::Fixed{T,f}) where {T,f} = Fixed{T,f}(x.i-y.i,0)
3232

3333
# with truncation:
3434
#*{f}(x::Fixed32{f}, y::Fixed32{f}) = Fixed32{f}(Base.widemul(x.i,y.i)>>f,0)
3535
# with rounding up:
36-
*{T,f}(x::Fixed{T,f}, y::Fixed{T,f}) = Fixed{T,f}((Base.widemul(x.i,y.i) + (convert(widen(T), 1) << (f-1) ))>>f,0)
36+
*(x::Fixed{T,f}, y::Fixed{T,f}) where {T,f} = Fixed{T,f}((Base.widemul(x.i,y.i) + (convert(widen(T), 1) << (f-1) ))>>f,0)
3737

38-
/{T,f}(x::Fixed{T,f}, y::Fixed{T,f}) = Fixed{T,f}(div(convert(widen(T), x.i) << f, y.i), 0)
38+
/(x::Fixed{T,f}, y::Fixed{T,f}) where {T,f} = Fixed{T,f}(div(convert(widen(T), x.i) << f, y.i), 0)
3939

4040

4141
# # conversions and promotions
42-
convert{T,f}(::Type{Fixed{T,f}}, x::Integer) = Fixed{T,f}(round(T, convert(widen1(T),x)<<f),0)
43-
convert{T,f}(::Type{Fixed{T,f}}, x::AbstractFloat) = Fixed{T,f}(round(T, trunc(widen1(T),x)<<f + rem(x,1)*(1<<f)),0)
44-
convert{T,f}(::Type{Fixed{T,f}}, x::Rational) = Fixed{T,f}(x.num)/Fixed{T,f}(x.den)
42+
convert(::Type{Fixed{T,f}}, x::Integer) where {T,f} = Fixed{T,f}(round(T, convert(widen1(T),x)<<f),0)
43+
convert(::Type{Fixed{T,f}}, x::AbstractFloat) where {T,f} = Fixed{T,f}(round(T, trunc(widen1(T),x)<<f + rem(x,1)*(1<<f)),0)
44+
convert(::Type{Fixed{T,f}}, x::Rational) where {T,f} = Fixed{T,f}(x.num)/Fixed{T,f}(x.den)
4545

46-
rem{T,f}(x::Integer, ::Type{Fixed{T,f}}) = Fixed{T,f}(rem(x,T)<<f,0)
47-
rem{T,f}(x::Real, ::Type{Fixed{T,f}}) = Fixed{T,f}(rem(Integer(trunc(x)),T)<<f + rem(Integer(round(rem(x,1)*(1<<f))),T),0)
46+
rem(x::Integer, ::Type{Fixed{T,f}}) where {T,f} = Fixed{T,f}(rem(x,T)<<f,0)
47+
rem(x::Real, ::Type{Fixed{T,f}}) where {T,f} = Fixed{T,f}(rem(Integer(trunc(x)),T)<<f + rem(Integer(round(rem(x,1)*(1<<f))),T),0)
4848

4949
# convert{T,f}(::Type{AbstractFloat}, x::Fixed{T,f}) = convert(floattype(x), x)
5050
float(x::Fixed) = convert(floattype(x), x)
5151

52-
convert{T,f}(::Type{BigFloat}, x::Fixed{T,f}) =
52+
convert(::Type{BigFloat}, x::Fixed{T,f}) where {T,f} =
5353
convert(BigFloat,x.i>>f) + convert(BigFloat,x.i&(1<<f - 1))/convert(BigFloat,1<<f)
54-
convert{TF<:AbstractFloat,T,f}(::Type{TF}, x::Fixed{T,f}) =
54+
convert(::Type{TF}, x::Fixed{T,f}) where {TF <: AbstractFloat,T,f} =
5555
convert(TF,x.i>>f) + convert(TF,x.i&(1<<f - 1))/convert(TF,1<<f)
5656

57-
convert{T,f}(::Type{Bool}, x::Fixed{T,f}) = x.i!=0
58-
function convert{T,f}(::Type{Integer}, x::Fixed{T,f})
57+
convert(::Type{Bool}, x::Fixed{T,f}) where {T,f} = x.i!=0
58+
function convert(::Type{Integer}, x::Fixed{T,f}) where {T,f}
5959
isinteger(x) || throw(InexactError())
6060
convert(Integer, x.i>>f)
6161
end
62-
function convert{TI<:Integer, T,f}(::Type{TI}, x::Fixed{T,f})
62+
function convert(::Type{TI}, x::Fixed{T,f}) where {TI <: Integer,T,f}
6363
isinteger(x) || throw(InexactError())
6464
convert(TI, x.i>>f)
6565
end
6666

67-
convert{TR<:Rational,T,f}(::Type{TR}, x::Fixed{T,f}) =
67+
convert(::Type{TR}, x::Fixed{T,f}) where {TR <: Rational,T,f} =
6868
convert(TR, x.i>>f + (x.i&(1<<f-1))//(1<<f))
6969

70-
promote_rule{T,f,TI<:Integer}(ft::Type{Fixed{T,f}}, ::Type{TI}) = Fixed{T,f}
71-
promote_rule{T,f,TF<:AbstractFloat}(::Type{Fixed{T,f}}, ::Type{TF}) = TF
72-
promote_rule{T,f,TR}(::Type{Fixed{T,f}}, ::Type{Rational{TR}}) = Rational{TR}
70+
promote_rule(ft::Type{Fixed{T,f}}, ::Type{TI}) where {T,f,TI <: Integer} = Fixed{T,f}
71+
promote_rule(::Type{Fixed{T,f}}, ::Type{TF}) where {T,f,TF <: AbstractFloat} = TF
72+
promote_rule(::Type{Fixed{T,f}}, ::Type{Rational{TR}}) where {T,f,TR} = Rational{TR}
7373

7474
# TODO: Document and check that it still does the right thing.
75-
decompose{T,f}(x::Fixed{T,f}) = x.i, -f, 1
75+
decompose(x::Fixed{T,f}) where {T,f} = x.i, -f, 1

0 commit comments

Comments
 (0)