Skip to content

Commit

Permalink
Fix Float16 conversion from large Float32s (JuliaLang#33084)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Aug 29, 2019
1 parent ce6dff0 commit 7bc7904
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function Float16(val::Float32)
# NOTE: we maybe should ignore NaNs here, but the payload is
# getting truncated anyway so "rounding" it might not matter
nextbit = (f >> (sh-1)) & 1
if nextbit != 0
if nextbit != 0 && (h & 0x7C00) != 0x7C00
# Round halfway to even or check lower bits
if h&1 == 1 || (f & ((1<<(sh-1))-1)) != 0
h += UInt16(1)
Expand Down
3 changes: 3 additions & 0 deletions test/float16.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,6 @@ const minsubf16_32 = Float32(minsubf16)
# Ties to even, in this case up
@test Float16(minsubf16_32 + f16eps2) == nextfloat(minsubf16)
@test Float16(prevfloat(minsubf16_32 + f16eps2)) == minsubf16

# issues #33076
@test Float16(1f5) == Inf16

0 comments on commit 7bc7904

Please sign in to comment.