Skip to content

Commit ccb4267

Browse files
authored
Merge pull request #60 from JuliaMath/teh/show
Don't use Float32 in printing
2 parents a00d54c + 15346e8 commit ccb4267

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

src/FixedPointNumbers.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,10 @@ widen1(::Type{Int64}) = Int128
8484
widen1(::Type{UInt64}) = UInt128
8585
widen1(x::Integer) = x % widen1(typeof(x))
8686

87-
if VERSION <= v"0.5.0-dev+755"
88-
@generated function floattype{T,f}(::Type{FixedPoint{T,f}})
89-
f>22 ? :(Float64) : :(Float32)
90-
end
91-
else
92-
@pure function floattype{T,f}(::Type{FixedPoint{T,f}})
93-
f>22 ? Float64 : Float32
94-
end
95-
end
87+
typealias ShortInts Union{Int8,UInt8,Int16,UInt16}
88+
89+
floattype{T<:ShortInts,f}(::Type{FixedPoint{T,f}}) = Float32
90+
floattype{T,f}(::Type{FixedPoint{T,f}}) = Float64
9691
floattype(x::FixedPoint) = floattype(supertype(typeof(x)))
9792

9893

@@ -155,7 +150,7 @@ function show{T,f}(io::IO, x::FixedPoint{T,f})
155150
print(io, ")")
156151
end
157152
const _log2_10 = 3.321928094887362
158-
showcompact{T,f}(io::IO, x::FixedPoint{T,f}) = show(io, round(float(x), ceil(Int,f/_log2_10)))
153+
showcompact{T,f}(io::IO, x::FixedPoint{T,f}) = show(io, round(Float64(x), ceil(Int,f/_log2_10)))
159154

160155
@noinline function throw_converterror{T<:FixedPoint}(::Type{T}, x)
161156
n = 2^(8*sizeof(T))

test/fixed.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ end
103103

104104
# Floating-point conversions
105105
@test isa(float(one(Fixed{Int8,6})), Float32)
106-
@test isa(float(one(Fixed{Int32,18})), Float32)
106+
@test isa(float(one(Fixed{Int32,18})), Float64)
107107
@test isa(float(one(Fixed{Int32,25})), Float64)
108108

109109
# Show

test/ufixed.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ x = UFixed8(0b01010001, 0)
112112
@test -x == 0xafuf8
113113

114114
@test isa(float(one(UFixed{UInt8,7})), Float32)
115-
@test isa(float(one(UFixed{UInt32,18})), Float32)
115+
@test isa(float(one(UFixed{UInt32,18})), Float64)
116116
@test isa(float(one(UFixed{UInt32,25})), Float64)
117117

118118
for T in (FixedPointNumbers.UF..., UF2...)
@@ -234,8 +234,7 @@ x = 0xaauf8
234234
iob = IOBuffer()
235235
show(iob, x)
236236
str = takebuf_string(iob)
237-
@test startswith(str, "UFixed{UInt8,8}(")
238-
@test eval(parse(str)) == x
237+
@test str == "UFixed{UInt8,8}(0.667)"
239238

240239
# scaledual
241240
function generic_scale!(C::AbstractArray, X::AbstractArray, s::Number)

0 commit comments

Comments
 (0)