From 0a9ae2f8ab879a468823a907a8c4709166302a6e Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 30 Jan 2019 11:08:10 -0500 Subject: [PATCH 1/2] add `bswap` method for `Float16` --- base/float.jl | 1 + test/numbers.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/base/float.jl b/base/float.jl index 28254437c8c08..e57cce15aa795 100644 --- a/base/float.jl +++ b/base/float.jl @@ -841,6 +841,7 @@ eps(::AbstractFloat) ## byte order swaps for arbitrary-endianness serialization/deserialization ## +bswap(x::Float16) = bswap_int(x) bswap(x::Float32) = bswap_int(x) bswap(x::Float64) = bswap_int(x) diff --git a/test/numbers.jl b/test/numbers.jl index b9876a321346e..952cf67c36d03 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2180,8 +2180,10 @@ end @test bswap(0x01020304) === 0x04030201 @test reinterpret(Float64,bswap(0x000000000000f03f)) === 1.0 @test reinterpret(Float32,bswap(0x0000c03f)) === 1.5f0 + @test reinterpret(Float16,bswap(0x003c)) === Float16(1.0) @test bswap(reinterpret(Float64,0x000000000000f03f)) === 1.0 @test bswap(reinterpret(Float32,0x0000c03f)) === 1.5f0 + @test bswap(reinterpret(Float16,0x003e)) === Float16(1.5) 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]) From a4aea89b4b6786ae7461c9ac1fcfc2cff93d5fc8 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 30 Jan 2019 11:23:20 -0500 Subject: [PATCH 2/2] Update float.jl --- base/float.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/base/float.jl b/base/float.jl index e57cce15aa795..5cd74bf2c2a6d 100644 --- a/base/float.jl +++ b/base/float.jl @@ -841,9 +841,7 @@ eps(::AbstractFloat) ## byte order swaps for arbitrary-endianness serialization/deserialization ## -bswap(x::Float16) = bswap_int(x) -bswap(x::Float32) = bswap_int(x) -bswap(x::Float64) = bswap_int(x) +bswap(x::IEEEFloat) = bswap_int(x) # bit patterns reinterpret(::Type{Unsigned}, x::Float64) = reinterpret(UInt64, x)