Skip to content

Commit 1896a57

Browse files
zygmuntszpaktkelman
authored andcommitted
Add tests for convert
Added tests for `convert(::Type{Int128}, x::Float16)` and `convert(::Type{UInt128}, x::Float16)` which validate type and check that `InexactError` is thrown for some cases where it should be thrown e.g.: `@test_throws InexactError convert(UInt128, Float16(3.5))` and `@test_throws InexactError convert(UInt128, Float16(-1))` (cherry picked from commit 809eda9) ref #14080
1 parent 8d7683e commit 1896a57

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/float16.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ g = Float16(1.)
2323
@test convert(Int128,Float16(-2.0)) == Int128(-2)
2424
@test convert(UInt128,Float16(2.0)) == UInt128(2)
2525

26+
# convert(::Type{Int128}, x::Float16)
27+
@test convert(Int128, Float16(1.0)) === Int128(1.0)
28+
@test convert(Int128, Float16(-1.0)) === Int128(-1.0)
29+
@test_throws InexactError convert(Int128, Float16(3.5))
30+
31+
# convert(::Type{UInt128}, x::Float16)
32+
@test convert(UInt128, Float16(1.0)) === UInt128(1.0)
33+
@test_throws InexactError convert(UInt128, Float16(3.5))
34+
@test_throws InexactError convert(UInt128, Float16(-1))
35+
2636
x = Float32(rand())
2737
y = Float32(rand())
2838
z = Float32(rand())

0 commit comments

Comments
 (0)