Skip to content

Commit

Permalink
Merge pull request #346 from traktofon/complex-bswap
Browse files Browse the repository at this point in the history
Backport bswap method for complex numbers.
  • Loading branch information
vchuravy committed Apr 12, 2017
2 parents fc6af82 + 7a1200a commit 47f5741
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `unsafe_trunc(::Type{<:Integer}, ::Integer)` is supported on 0.5. ([#18629])

* `bswap` is supported for `Complex` arguments on 0.5 and below. ([#21346])

## Renamed functions

* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively
Expand Down Expand Up @@ -358,3 +360,4 @@ includes this fix. Find the minimum version from there.
[#20418]: https://github.com/JuliaLang/julia/issues/20418
[#20500]: https://github.com/JuliaLang/julia/issues/20500
[#18629]: https://github.com/JuliaLang/julia/pull/18629
[#21346]: https://github.com/JuliaLang/julia/pull/21346
5 changes: 5 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,11 @@ if VERSION < v"0.6.0-dev.735"
Base.unsafe_trunc{T<:Integer}(::Type{T}, x::Integer) = rem(x, T)
end

# https://github.com/JuliaLang/julia/pull/21346
if VERSION < v"0.6.0-pre.beta.102"
Base.bswap(z::Complex) = Complex(bswap(real(z)), bswap(imag(z)))
end

include("to-be-deprecated.jl")

end # module Compat
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,16 @@ end
@test unsafe_trunc(Int8, 128) === Int8(-128)
@test_throws InexactError trunc(Int8, 128)

# PR 21346
let zbuf = IOBuffer([0xbf, 0xc0, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00,
0x40, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
z1 = read(zbuf, Complex64)
z2 = read(zbuf, Complex128)
@test bswap(z1) === -1.5f0 + 2.5f0im
@test bswap(z2) === 3.5 - 4.5im
end

include("to-be-deprecated.jl")

nothing

0 comments on commit 47f5741

Please sign in to comment.