diff --git a/src/bfloat16.jl b/src/bfloat16.jl index a643df9..3bc8e7b 100644 --- a/src/bfloat16.jl +++ b/src/bfloat16.jl @@ -220,6 +220,10 @@ else end end +# BigFloat conversion +BFloat16(x::BigFloat) = BFloat16(Float32(x)) +Base.BigFloat(x::BFloat16) = BigFloat(Float32(x)) + # Basic arithmetic if llvm_arithmetic +(x::T, y::T) where {T<:BFloat16} = Base.add_float(x, y) diff --git a/test/runtests.jl b/test/runtests.jl index 908ddf6..452281c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -27,6 +27,8 @@ end @test Float64(BFloat16(10)) == 10.0 @test Int32(BFloat16(10)) == Int32(10) @test Int64(BFloat16(10)) == Int64(10) + @test BFloat16(BigFloat(1)) == BFloat16(1) + @test BigFloat(BFloat16(1)) == BigFloat(1) end @testset "abi" begin