Skip to content

Commit 6612826

Browse files
committed
Fix float16 test
Do not use `rand()` and test both round up and down in different functions. Closes #15993
1 parent 17dfdc1 commit 6612826

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

test/float16.jl

+18-14
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,24 @@ g = Float16(1.)
3333
@test_throws InexactError convert(UInt128, Float16(3.5))
3434
@test_throws InexactError convert(UInt128, Float16(-1))
3535

36-
x = Float32(rand())
37-
y = Float32(rand())
38-
z = Float32(rand())
39-
@test_approx_eq Float16(x)^2 Float16(x^2)
40-
@test round(Int,Float16(x)) == round(Int,x)
41-
@test trunc(Int,Float16(x)) == trunc(Int,x)
42-
@test floor(Int,Float16(x)) == floor(Int,x)
43-
@test ceil(Int,Float16(x)) == ceil(Int,x)
44-
@test round(Float16(x)) == round(x)
45-
@test trunc(Float16(x)) == trunc(x)
46-
@test floor(Float16(x)) == floor(x)
47-
@test ceil(Float16(x)) == ceil(x)
48-
@test_approx_eq fma(Float16(x),Float16(y),Float16(z)) fma(x,y,z)
49-
@test_approx_eq muladd(Float16(x),Float16(y),Float16(z)) muladd(x,y,z)
36+
@test_approx_eq Float16(0.5f0)^2 Float16(0.5f0^2)
37+
@test round(Int,Float16(0.5f0)) == round(Int,0.5f0)
38+
@test trunc(Int,Float16(0.9f0)) === trunc(Int,0.9f0) === 0
39+
@test floor(Int,Float16(0.9f0)) === floor(Int,0.9f0) === 0
40+
@test trunc(Int,Float16(1)) === 1
41+
@test floor(Int,Float16(1)) === 1
42+
@test ceil(Int,Float16(0.1f0)) === ceil(Int,0.1f0) === 1
43+
@test ceil(Int,Float16(0)) === ceil(Int,0) === 0
44+
@test round(Float16(0.1f0)) == round(0.1f0) == 0
45+
@test round(Float16(0.9f0)) == round(0.9f0) == 1
46+
@test trunc(Float16(0.9f0)) == trunc(0.9f0) == 0
47+
@test floor(Float16(0.9f0)) == floor(0.9f0) == 0
48+
@test trunc(Float16(1)) === Float16(1)
49+
@test floor(Float16(1)) === Float16(1)
50+
@test ceil(Float16(0.1)) == ceil(0.1)
51+
@test ceil(Float16(0.9)) == ceil(0.9)
52+
@test_approx_eq fma(Float16(0.1),Float16(0.9),Float16(0.5)) fma(0.1,0.9,0.5)
53+
@test_approx_eq muladd(Float16(0.1),Float16(0.9),Float16(0.5)) muladd(0.1,0.9,0.5)
5054
@test convert(Int128,Float16(-1.0)) == Int128(-1)
5155
@test convert(UInt128,Float16(5.0)) == UInt128(5)
5256

0 commit comments

Comments
 (0)