From 89650b7c0e9dc1f8b5ab81be522ecb565c12da31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Kl=C3=B6wer?= Date: Thu, 28 Dec 2023 15:24:50 +0100 Subject: [PATCH 1/2] BFloat16(::BigFloat) and BigFloat(::BFloat16) --- src/bfloat16.jl | 4 ++++ 1 file changed, 4 insertions(+) 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) From e415c2990afe7aca76f6565f1a686bb8af03dd9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Kl=C3=B6wer?= Date: Thu, 28 Dec 2023 15:31:49 +0100 Subject: [PATCH 2/2] BigFloat-BFloat16 conversion tests added --- test/runtests.jl | 2 ++ 1 file changed, 2 insertions(+) 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