From d6edf6a517da17ee3604982180ec370e993d2e85 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 24 Jun 2014 16:51:15 -0400 Subject: [PATCH] fix #7390 --- NEWS.md | 3 +++ base/float.jl | 12 ++++++------ test/bitarray.jl | 26 +++++++++++++------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/NEWS.md b/NEWS.md index adfba2b33de9c..cb08592b92cd4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -171,6 +171,9 @@ Library improvements * `polygamma`, `digamma`, and `trigamma` now accept complex arguments, and `zeta(s, z)` now provides the Hurwitz zeta ([#7125]). + * Narrow integer types (< 32 bits) are promoted to `Float64` rather + than to `Float32` by `float(x)` ([#7390]). + * `String` improvements * Triple-quoted regex strings, `r"""..."""` ([#4934]). diff --git a/base/float.jl b/base/float.jl index fa47113ce6897..7b952b7c0351e 100644 --- a/base/float.jl +++ b/base/float.jl @@ -37,15 +37,15 @@ convert(::Type{Float32}, x::Float64) = box(Float32,fptrunc(Float32,x)) convert(::Type{Float64}, x::Float16) = convert(Float64, convert(Float32,x)) convert(::Type{Float64}, x::Float32) = box(Float64,fpext(Float64,x)) -convert(::Type{FloatingPoint}, x::Bool) = convert(Float32, x) -convert(::Type{FloatingPoint}, x::Char) = convert(Float32, x) -convert(::Type{FloatingPoint}, x::Int8) = convert(Float32, x) -convert(::Type{FloatingPoint}, x::Int16) = convert(Float32, x) +convert(::Type{FloatingPoint}, x::Bool) = convert(Float64, x) +convert(::Type{FloatingPoint}, x::Char) = convert(Float64, x) +convert(::Type{FloatingPoint}, x::Int8) = convert(Float64, x) +convert(::Type{FloatingPoint}, x::Int16) = convert(Float64, x) convert(::Type{FloatingPoint}, x::Int32) = convert(Float64, x) convert(::Type{FloatingPoint}, x::Int64) = convert(Float64, x) # LOSSY convert(::Type{FloatingPoint}, x::Int128) = convert(Float64, x) # LOSSY -convert(::Type{FloatingPoint}, x::Uint8) = convert(Float32, x) -convert(::Type{FloatingPoint}, x::Uint16) = convert(Float32, x) +convert(::Type{FloatingPoint}, x::Uint8) = convert(Float64, x) +convert(::Type{FloatingPoint}, x::Uint16) = convert(Float64, x) convert(::Type{FloatingPoint}, x::Uint32) = convert(Float64, x) convert(::Type{FloatingPoint}, x::Uint64) = convert(Float64, x) # LOSSY convert(::Type{FloatingPoint}, x::Uint128) = convert(Float64, x) # LOSSY diff --git a/test/bitarray.jl b/test/bitarray.jl index 00f804de0481d..780e6815caf47 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -550,7 +550,7 @@ b2 = randbool(n1, n2) @check_bit_operation (+)(b1, b2) Matrix{Int} @check_bit_operation (-)(b1, b2) Matrix{Int} @check_bit_operation (.*)(b1, b2) BitMatrix -@check_bit_operation (./)(b1, b2) Matrix{Float32} +@check_bit_operation (./)(b1, b2) Matrix{Float64} @check_bit_operation (.^)(b1, b2) BitMatrix b2 = trues(n1, n2) @@ -567,8 +567,8 @@ end b2 = randbool(n1, n1) @check_bit_operation (*)(b1, b2) Matrix{Int} -@check_bit_operation (/)(b1, b1) Matrix{Float32} -@check_bit_operation (\)(b1, b1) Matrix{Float32} +@check_bit_operation (/)(b1, b1) Matrix{Float64} +@check_bit_operation (\)(b1, b1) Matrix{Float64} b0 = falses(0) @check_bit_operation (&)(b0, b0) BitVector @@ -633,10 +633,10 @@ for (x1,t1) = {(f1, Float64), end b2 = trues(n1, n2) -@check_bit_operation (./)(true, b2) Matrix{Float32} +@check_bit_operation (./)(true, b2) Matrix{Float64} @check_bit_operation div(true, b2) BitMatrix @check_bit_operation mod(true, b2) BitMatrix -@check_bit_operation (./)(false, b2) Matrix{Float32} +@check_bit_operation (./)(false, b2) Matrix{Float64} @check_bit_operation div(false, b2) BitMatrix @check_bit_operation mod(false, b2) BitMatrix @@ -644,7 +644,7 @@ b2 = trues(n1, n2) @check_bit_operation div(i1, b2) Matrix{Int} @check_bit_operation mod(i1, b2) Matrix{Int} -@check_bit_operation (./)(u1, b2) Matrix{Float32} +@check_bit_operation (./)(u1, b2) Matrix{Float64} @check_bit_operation div(u1, b2) Matrix{Uint8} @check_bit_operation mod(u1, b2) Matrix{Uint8} @@ -653,7 +653,7 @@ b2 = trues(n1, n2) @check_bit_operation mod(f1, b2) Matrix{Float64} @check_bit_operation (./)(ci1, b2) Matrix{Complex128} -@check_bit_operation (./)(cu1, b2) Matrix{Complex64} +@check_bit_operation (./)(cu1, b2) Matrix{Complex128} @check_bit_operation (./)(cf1, b2) Matrix{Complex128} b2 = randbool(n1, n2) @@ -694,8 +694,8 @@ cf2 = complex(f2) @check_bit_operation (.-)(b1, false) Matrix{Int} @check_bit_operation (.*)(b1, true) BitMatrix @check_bit_operation (.*)(b1, false) BitMatrix -@check_bit_operation (./)(b1, true) Matrix{Float32} -@check_bit_operation (./)(b1, false) Matrix{Float32} +@check_bit_operation (./)(b1, true) Matrix{Float64} +@check_bit_operation (./)(b1, false) Matrix{Float64} @check_bit_operation div(b1, true) BitMatrix @check_bit_operation mod(b1, true) BitMatrix @@ -715,7 +715,7 @@ cf2 = complex(f2) @check_bit_operation (.+)(b1, u2) Matrix{Uint8} @check_bit_operation (.-)(b1, u2) Matrix{Uint8} @check_bit_operation (.*)(b1, u2) Matrix{Uint8} -@check_bit_operation (./)(b1, u2) Matrix{Float32} +@check_bit_operation (./)(b1, u2) Matrix{Float64} @check_bit_operation div(b1, u2) Matrix{Uint8} @check_bit_operation mod(b1, u2) Matrix{Uint8} @@ -734,7 +734,7 @@ cf2 = complex(f2) @check_bit_operation (.+)(b1, cu2) Matrix{Complex{Uint8}} @check_bit_operation (.-)(b1, cu2) Matrix{Complex{Uint8}} @check_bit_operation (.*)(b1, cu2) Matrix{Complex{Uint8}} -@check_bit_operation (./)(b1, cu2) Matrix{Complex64} +@check_bit_operation (./)(b1, cu2) Matrix{Complex128} @check_bit_operation (.+)(b1, cf2) Matrix{Complex128} @check_bit_operation (.-)(b1, cf2) Matrix{Complex128} @@ -751,7 +751,7 @@ cf2 = complex(f2) @check_bit_operation (.^)(b1, 0.0) Matrix{Float64} @check_bit_operation (.^)(b1, 1.0) Matrix{Float64} @check_bit_operation (.^)(b1, 0.0im) Matrix{Complex128} -@check_bit_operation (.^)(b1, 0x0im) Matrix{Complex64} +@check_bit_operation (.^)(b1, 0x0im) Matrix{Complex128} @check_bit_operation (.^)(b1, 0im) Matrix{Complex128} b1 = trues(n1, n2) @@ -759,7 +759,7 @@ b1 = trues(n1, n2) @check_bit_operation (.^)(b1, 1.0im) Matrix{Complex128} @check_bit_operation (.^)(b1, -1im) Matrix{Complex128} @check_bit_operation (.^)(b1, 1im) Matrix{Complex128} -@check_bit_operation (.^)(b1, 0x1im) Matrix{Complex64} +@check_bit_operation (.^)(b1, 0x1im) Matrix{Complex128} timesofar("binary arithmetic")