Skip to content

Commit 7188a96

Browse files
authored
Merge pull request #64 from JuliaMath/vc/0.6
WIP: 0.6 compatibility
2 parents ac602bb + f76ef21 commit 7188a96

8 files changed

Lines changed: 32 additions & 26 deletions

File tree

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
julia 0.5
2-
Compat 0.9.1
2+
Compat 0.9.5

src/FixedPointNumbers.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ else
2121
end
2222

2323
using Compat
24+
import Compat.String
2425

2526
# T => BaseType
2627
# f => Number of Bytes reserved for fractional part
@@ -83,6 +84,7 @@ widen1(::Type{Int32}) = Int64
8384
widen1(::Type{UInt32}) = UInt64
8485
widen1(::Type{Int64}) = Int128
8586
widen1(::Type{UInt64}) = UInt128
87+
widen1(::Type{UInt128}) = UInt128
8688
widen1(x::Integer) = x % widen1(typeof(x))
8789

8890
typealias ShortInts Union{Int8,UInt8,Int16,UInt16}
@@ -157,8 +159,8 @@ scaledual{Tdual<:Number, T<:FixedPoint}(b::Tdual, x::Union{T,AbstractArray{T}})
157159
n = 2^(8*sizeof(T))
158160
bitstring = sizeof(T) == 1 ? "an 8-bit" : "a $(8*sizeof(T))-bit"
159161
io = IOBuffer()
160-
showcompact(io, typemin(T)); Tmin = takebuf_string(io)
161-
showcompact(io, typemax(T)); Tmax = takebuf_string(io)
162+
showcompact(io, typemin(T)); Tmin = String(take!(io))
163+
showcompact(io, typemax(T)); Tmax = String(take!(io))
162164
throw(ArgumentError("$T is $bitstring type representing $n values from $Tmin to $Tmax; cannot represent $x"))
163165
end
164166

src/deprecations.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function *{T,f}(n::Integer, ::NormedConstructor{T,f})
4141
i = 8*sizeof(T)-f
4242
io = IOBuffer()
4343
show(io, n)
44-
nstr = takebuf_string(io)
44+
nstr = String(take!(io))
4545
cstr = typeof(n) == T ? nstr : "convert($T, $nstr)"
4646
Base.depwarn("$(nstr)uf$f is deprecated, please use reinterpret(N$(i)f$f, $cstr) instead", :*)
4747
reinterpret(Normed{T,f}, convert(T, n))
@@ -54,4 +54,3 @@ const uf16 = NormedConstructor{UInt16,16}()
5454

5555
@deprecate_binding UfixedConstructor NormedConstructor
5656
@deprecate_binding UFixedConstructor NormedConstructor
57-

src/fixed.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ signbits{X<:Fixed}(::Type{X}) = 1
1919

2020
for T in (Int8, Int16, Int32, Int64)
2121
for f in 0:sizeof(T)*8-1
22-
sym = Symbol(takebuf_string(showtype(_iotypealias, Fixed{T,f})))
22+
sym = Symbol(String(take!(showtype(_iotypealias, Fixed{T,f}))))
2323
@eval begin
2424
typealias $sym Fixed{$T,$f}
2525
export $sym

src/normed.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ signbits{X<:Normed}(::Type{X}) = 0
1717

1818
for T in (UInt8, UInt16, UInt32, UInt64)
1919
for f in 0:sizeof(T)*8
20-
sym = Symbol(takebuf_string(showtype(_iotypealias, Normed{T,f})))
20+
sym = Symbol(String(take!(showtype(_iotypealias, Normed{T,f}))))
2121
@eval begin
2222
typealias $sym Normed{$T,$f}
2323
export $sym
@@ -37,15 +37,17 @@ rawone(v) = reinterpret(one(v))
3737

3838
# Conversions
3939
convert{T<:Normed}(::Type{T}, x::T) = x
40-
convert{T1,T2,f}(::Type{Normed{T1,f}}, x::Normed{T2,f}) = Normed{T1,f}(convert(T1, x.i), 0)
41-
function convert{T,T2,f}(::Type{Normed{T,f}}, x::Normed{T2})
40+
convert{T1<:Unsigned,T2<:Unsigned,f}(::Type{Normed{T1,f}}, x::Normed{T2,f}) = Normed{T1,f}(convert(T1, x.i), 0)
41+
function convert{T<:Unsigned,T2<:Unsigned,f}(::Type{Normed{T,f}}, x::Normed{T2})
4242
U = Normed{T,f}
4343
y = round((rawone(U)/rawone(x))*reinterpret(x))
4444
(0 <= y) & (y <= typemax(T)) || throw_converterror(U, x)
4545
reinterpret(U, _unsafe_trunc(T, y))
4646
end
47-
convert(::Type{N0f16}, x::N0f8) = reinterpret(N0f16, convert(UInt16, 0x0101*reinterpret(x)))
4847
convert{U<:Normed}(::Type{U}, x::Real) = _convert(U, rawtype(U), x)
48+
convert{T1,T2,f}(::Type{Normed{T1,f}}, x::Normed{T2,f}) = Normed{T1,f}(convert(T1, x.i), 0)
49+
50+
convert(::Type{N0f16}, x::N0f8) = reinterpret(N0f16, convert(UInt16, 0x0101*reinterpret(x)))
4951
function _convert{U<:Normed,T}(::Type{U}, ::Type{T}, x)
5052
y = round(widen1(rawone(U))*x)
5153
(0 <= y) & (y <= typemax(T)) || throw_converterror(U, x)

test/fixed.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Base.Test
22
using FixedPointNumbers
3+
using Compat
4+
import Compat.String
35

46
function test_op{F,T}(fun::F, ::Type{T}, fx, fy, fxf, fyf, tol)
57
# Make sure that the result is representable
@@ -50,8 +52,8 @@ function test_fixed{T}(::Type{T}, f)
5052
end
5153
end
5254

53-
@test_approx_eq_eps convert(Fixed{Int8,7}, 0.8) 0.797 0.001
54-
@test_approx_eq_eps convert(Fixed{Int8,7}, 0.9) 0.898 0.001
55+
@test isapprox(convert(Fixed{Int8,7}, 0.8), 0.797, atol=0.001)
56+
@test isapprox(convert(Fixed{Int8,7}, 0.9), 0.898, atol=0.001)
5557
@test_throws InexactError convert(Fixed{Int8, 7}, 0.999)
5658
@test_throws InexactError convert(Fixed{Int8, 7}, 1.0)
5759
@test_throws InexactError convert(Fixed{Int8, 7}, 1)
@@ -110,7 +112,7 @@ end
110112
x = Fixed{Int32,5}(0.25)
111113
iob = IOBuffer()
112114
show(iob, x)
113-
str = takebuf_string(iob)
115+
str = String(take!(iob))
114116
@test str == "0.25Q26f5"
115117
@test eval(parse(str)) == x
116118

test/normed.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using FixedPointNumbers
22
using Base.Test
33
using Compat
4+
import Compat.String
45

56
@test reinterpret(N0f8, 0xa2).i === 0xa2
67
@test reinterpret(N6f10, 0x1fa2).i === 0x1fa2
@@ -132,14 +133,14 @@ for T in (FixedPointNumbers.UF..., UF2...)
132133
@test typeof((x+y)-y) == T
133134
@test typeof(x*y) == T
134135
@test typeof(x/y) == T
135-
@test_approx_eq(x+y, T(0x35,0))
136-
@test_approx_eq((x+y)-x, fy)
137-
@test_approx_eq((x-y)+y, fx)
138-
@test_approx_eq(x*y, convert(T, fx*fy))
139-
@test_approx_eq(x/y, convert(T, fx/fy))
140-
@test_approx_eq(x^2, convert(T, fx^2))
141-
@test_approx_eq(x^2.1f0, fx^2.1f0)
142-
@test_approx_eq(x^2.1, convert(Float64, x)^2.1)
136+
@test (x+y) T(0x35,0)
137+
@test ((x+y)-x) fy
138+
@test ((x-y)+y) fx
139+
@test (x*y) convert(T, fx*fy)
140+
@test (x/y) convert(T, fx/fy)
141+
@test (x^2) convert(T, fx^2)
142+
@test (x^2.1f0) fx^2.1f0
143+
@test (x^2.1) convert(Float64, x)^2.1
143144
end
144145

145146
function testtrunc{T}(inc::T)
@@ -239,7 +240,7 @@ end
239240
x = reinterpret(N0f8, 0xaa)
240241
iob = IOBuffer()
241242
show(iob, x)
242-
str = takebuf_string(iob)
243+
str = String(take!(iob))
243244
@test str == "0.667N0f8"
244245
@test eval(parse(str)) == x
245246

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using FixedPointNumbers, Base.Test
22

3-
if VERSION >= v"0.5.0"
4-
@test isempty(detect_ambiguities(FixedPointNumbers, Base, Core))
5-
end
6-
73
for f in ["normed.jl", "fixed.jl"]
84
println("Testing $f")
95
include(f)
106
end
7+
8+
if v"0.5.0" <= VERSION < v"0.6.0-dev"
9+
@test isempty(detect_ambiguities(FixedPointNumbers, Base, Core))
10+
end

0 commit comments

Comments
 (0)