Skip to content

Conversion from Float64 to Float16 not always rounded to nearest #40315

Open
@goualard-f

Description

@goualard-f

Numbers 63328.0 and 63360.0 are perfectly representable in the Float16 format (with nextfloat(Float16(63328.0)) == Float16(63360.0)). The middle of the interval [63328.0,63360.0] is 63344.0. All Float64 in [63344.0, 63360.0] should round to Float16(63360.0); all Float64 in [63328.0,63344.0) should round to Float16(63328.0).

Yet with Julia 1.6.0, we have:

julia> convert(Float16,63343.99805) == 63328.0
false
julia> convert(Float16,63343.99805) == 63360.0
true

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions