Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Mar 5, 2025
1 parent dd57fbd commit 75ed265
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Test, BFloat16s, Printf, Random
@test Base.exponent_bits(BFloat16) == 8
@test Base.significand_bits(BFloat16) == 7
@test precision(BFloat16) == 8
@test Base.uinttype(BFloat16) == UInt16

@test typemin(BFloat16) == -BFloat16s.InfB16
@test typemax(BFloat16) == BFloat16s.InfB16
Expand Down Expand Up @@ -33,7 +34,7 @@ end
end

@testset "trunc" begin
bf_val = 5.5
bf_val = BFloat16(5.5)
@testset "$Ti" for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128)
@test trunc(Ti, bf_val) == Ti(5)
end
Expand All @@ -48,12 +49,17 @@ end
@test Float32(BFloat16(10)) == 1f1
@test Float64(BFloat16(10)) == 10.0
@test Int32(BFloat16(10)) == Int32(10)
@test UInt32(BFloat16(10)) == Int32(10)
@test Int64(BFloat16(10)) == Int64(10)
@test UInt64(BFloat16(10)) == Int64(10)
@test BFloat16(BigFloat(1)) == BFloat16(1)
@test BigFloat(BFloat16(1)) == BigFloat(1)
@test Float16(BFloat16(3.140625)) == Float16(π)
@test BFloat16(Float16(π)) == BFloat16(3.140625)

@test promote(BFloat16(4.5), Float64(5.0)) == (Float64(4.5), Float64(5.0))
@test promote(BFloat16(4.5), Float32(5.0)) == (Float32(4.5), Float32(5.0))

@test_throws InexactError Int8(BFloat16(500))
@test_throws InexactError UInt8(BFloat16(500))
end
Expand Down

0 comments on commit 75ed265

Please sign in to comment.