diff --git a/base/float.jl b/base/float.jl index fe07ffb6902a7..25102f652ad62 100644 --- a/base/float.jl +++ b/base/float.jl @@ -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) diff --git a/test/float16.jl b/test/float16.jl index d32387ee94277..4dd581f76538f 100644 --- a/test/float16.jl +++ b/test/float16.jl @@ -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