diff --git a/src/bfloat16.jl b/src/bfloat16.jl index 4148a2d..b3e06a6 100644 --- a/src/bfloat16.jl +++ b/src/bfloat16.jl @@ -245,7 +245,7 @@ else for f in (:+, :-, :*, :/, :^) @eval ($f)(x::BFloat16, y::BFloat16) = BFloat16($(f)(Float32(x), Float32(y))) end - -(x::BFloat16) = reinterpret(BFloat16, reinterpret(Unsigned, x) ⊻ sign_mask(BFloat16)) + -(x::BFloat16) = BFloat16(0) - x end ^(x::BFloat16, y::Integer) = BFloat16(Float32(x)^y) @@ -454,4 +454,4 @@ Base.read(io::IO, ::Type{BFloat16})::BFloat16 = reinterpret(BFloat16, read(io, U Base.bswap(x::BFloat16) = Base.bswap_int(x) # irrationals -BFloat16(x::AbstractIrrational) = BFloat16(Float32(x)::Float32) +BFloat16(x::AbstractIrrational) = BFloat16(Float32(x)::Float32) \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index d3524d5..f70f320 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -104,6 +104,9 @@ end @test zero(BFloat16) == BFloat16(0.0f0) @test one(BFloat16) == BFloat16(1.0) @test BFloat16(2.0) ^ -2 == BFloat16(0.25) + @test -one(BFloat16) == BFloat16(-1.0) + @test -zero(BFloat16) == BFloat16(-0.0) + @test -BFloat16(-1.0) == one(BFloat16) end @testset "printf" begin @@ -292,4 +295,4 @@ include("structure.jl") include("mathfuncs.jl") include("lowprecarrays.jl") -end # @testset "BFloat16s" +end # @testset "BFloat16s" \ No newline at end of file