@@ -2,6 +2,8 @@ using Test, BFloat16s, Printf, Random
2
2
3
3
@info " Testing BFloat16s" BFloat16s. llvm_storage BFloat16s. llvm_arithmetic
4
4
5
+ @testset " BFloat16s" begin
6
+
5
7
@testset " basics" begin
6
8
@test Base. exponent_bits (BFloat16) == 8
7
9
@test Base. significand_bits (BFloat16) == 7
35
37
36
38
@testset " trunc" begin
37
39
bf_val = BFloat16 (5.5 )
38
- @testset " $Ti " for Ti in (Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64)
39
- @test trunc (Ti, bf_val) == Ti (5 )
40
+ @testset " $Ti " for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128 )
41
+ @test trunc (Ti, bf_val) == Ti (5 ) skip = (BFloat16s . llvm_arithmetic && sizeof (Ti) == 16 )
40
42
end
41
43
42
44
@test trunc (BFloat16, Float32 (π)) == BFloat16 (3.140625 )
43
45
44
46
# InexactError
45
- @test_throws InexactError trunc (Int8,BFloat16 (500 ))
47
+ @test_throws InexactError trunc (Int16, typemax (BFloat16))
48
+ @test_throws InexactError trunc (UInt16, typemax (BFloat16))
46
49
end
47
50
48
51
@testset " conversions" begin
60
63
@test promote (BFloat16 (4.5 ), Float64 (5.0 )) == (Float64 (4.5 ), Float64 (5.0 ))
61
64
@test promote (BFloat16 (4.5 ), Float32 (5.0 )) == (Float32 (4.5 ), Float32 (5.0 ))
62
65
63
- @test_throws InexactError Int8 ( BFloat16 ( 500 ))
64
- @test_throws InexactError UInt8 ( BFloat16 ( 500 ))
66
+ @test_throws InexactError Int16 ( typemax (BFloat16 ))
67
+ @test_throws InexactError UInt16 ( typemax (BFloat16 ))
65
68
end
66
69
67
70
@testset " abi" begin
176
179
177
180
@test x < nextfloat (x)
178
181
@test x > prevfloat (x)
182
+
183
+ @test nextfloat (x, typemax (Int)) == typemax (BFloat16)
184
+ @test prevfloat (x, typemax (Int)) == typemin (BFloat16)
179
185
end
180
186
181
187
@test isnan (nextfloat (BFloat16s. NaNB16))
232
238
233
239
include (" structure.jl" )
234
240
include (" mathfuncs.jl" )
241
+
242
+ end # @testset "BFloat16s"
0 commit comments