Skip to content

Math.f16round gives wrong results for some values #5237

@ParthMozarkar

Description

@ParthMozarkar

I was going through the test262 conformance results and noticed that
Math.f16round is failing the value-conversion.js test.

After digging into it, I found that Math.f16round(1.00048828125000022204)
returns 1 instead of the correct value 1.0009765625.

The problem seems to be in how the float16 crate converts from f64 to f16
internally — it goes through f32 first, which causes double rounding and
produces the wrong result for certain inputs.

The fix would be to use the half crate's f16::from_f64 which is already
in the dependency tree and does the conversion correctly without going
through f32.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions