File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,11 @@ Base.exponent_bits(::Type{BFloat16}) = 8
63
63
Base. significand_bits (:: Type{BFloat16} ) = 7
64
64
Base. signbit (x:: BFloat16 ) = (reinterpret (Unsigned, x) & 0x8000 ) != = 0x0000
65
65
66
+ function Base. issubnormal (x:: BFloat16 )
67
+ y = reinterpret (Unsigned, x)
68
+ return (y & exponent_mask (BFloat16) == 0 ) & (y & significand_mask (BFloat16) != 0 )
69
+ end
70
+
66
71
function Base. significand (x:: BFloat16 )
67
72
xu = reinterpret (Unsigned, x)
68
73
xs = xu & ~ sign_mask (BFloat16)
Original file line number Diff line number Diff line change 22
22
@test significand (whole) == one (BFloat16)
23
23
24
24
# subnormal
25
- @test significand (reinterpret (BFloat16, 0b0000000000000001 )) == one (BFloat16)
26
-
25
+ @testset " subnormal" begin
26
+ allbfs = UInt16 (1 ): typemax (UInt16)
27
+ res = map (allbfs) do raw
28
+ bf = reinterpret (BFloat16, raw)
29
+ issubnormal (bf) == issubnormal (Float32 (bf))
30
+ end
31
+ @test all (res)
32
+ @test significand (reinterpret (BFloat16, 0b0000000000000001 )) == one (BFloat16)
33
+ end
27
34
@test frexp (phi) == (BFloat16 (0.80859375 ), 1 )
28
35
@test ldexp (BFloat16 (0.80859375 ), 1 ) == phi
29
36
You can’t perform that action at this time.
0 commit comments