Skip to content

Commit

Permalink
Merge pull request #7404 from stevengj/int8float
Browse files Browse the repository at this point in the history
fix #7390
  • Loading branch information
JeffBezanson committed Jun 25, 2014
2 parents be1aa2d + d6edf6a commit 14828f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down
12 changes: 6 additions & 6 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -633,18 +633,18 @@ 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

@check_bit_operation (./)(i1, b2) Matrix{Float64}
@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}

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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}

Expand All @@ -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}
Expand All @@ -751,15 +751,15 @@ 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)
@check_bit_operation (.^)(b1, -1.0im) Matrix{Complex128}
@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")

Expand Down

0 comments on commit 14828f6

Please sign in to comment.