Skip to content

Commit

Permalink
More/Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Mar 5, 2025
1 parent 1ececde commit 3391b17
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using Test, BFloat16s, Printf, Random

@info "Testing BFloat16s" BFloat16s.llvm_storage BFloat16s.llvm_arithmetic

@testset "BFloat16s" begin

@testset "basics" begin
@test Base.exponent_bits(BFloat16) == 8
@test Base.significand_bits(BFloat16) == 7
Expand Down Expand Up @@ -35,14 +37,15 @@ end

@testset "trunc" begin
bf_val = BFloat16(5.5)
@testset "$Ti" for Ti in (Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64)
@test trunc(Ti, bf_val) == Ti(5)
@testset "$Ti" for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128)
@test trunc(Ti, bf_val) == Ti(5) skip=(BFloat16s.llvm_arithmetic && sizeof(Ti) == 16)
end

@test trunc(BFloat16, Float32(π)) == BFloat16(3.140625)

#InexactError
@test_throws InexactError trunc(Int8,BFloat16(500))
@test_throws InexactError trunc(Int16, typemax(BFloat16))
@test_throws InexactError trunc(UInt16, typemax(BFloat16))
end

@testset "conversions" begin
Expand All @@ -60,8 +63,8 @@ end
@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))
@test_throws InexactError Int16(typemax(BFloat16))
@test_throws InexactError UInt16(typemax(BFloat16))
end

@testset "abi" begin
Expand Down Expand Up @@ -176,6 +179,9 @@ end

@test x < nextfloat(x)
@test x > prevfloat(x)

@test nextfloat(x, typemax(Int)) == typemax(BFloat16)
@test prevfloat(x, typemax(Int)) == typemin(BFloat16)
end

@test isnan(nextfloat(BFloat16s.NaNB16))
Expand Down Expand Up @@ -232,3 +238,5 @@ end

include("structure.jl")
include("mathfuncs.jl")

end # @testset "BFloat16s"

0 comments on commit 3391b17

Please sign in to comment.