Skip to content

Commit 7cf9374

Browse files
authored
BFloat16(::BigFloat) and BigFloat(::BFloat16) (#63)
1 parent 2811afa commit 7cf9374

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/bfloat16.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ else
222222
end
223223
end
224224

225+
# BigFloat conversion
226+
BFloat16(x::BigFloat) = BFloat16(Float32(x))
227+
Base.BigFloat(x::BFloat16) = BigFloat(Float32(x))
228+
225229
# Basic arithmetic
226230
if llvm_arithmetic
227231
+(x::T, y::T) where {T<:BFloat16} = Base.add_float(x, y)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ end
2727
@test Float64(BFloat16(10)) == 10.0
2828
@test Int32(BFloat16(10)) == Int32(10)
2929
@test Int64(BFloat16(10)) == Int64(10)
30+
@test BFloat16(BigFloat(1)) == BFloat16(1)
31+
@test BigFloat(BFloat16(1)) == BigFloat(1)
3032
end
3133

3234
@testset "abi" begin

0 commit comments

Comments
 (0)