Skip to content

Incorrect conversion from float64 to uint8. #733

Closed
@dmitshur

Description

@dmitshur

Say you start with a float64 value like 300.0. If you convert it to int, it becomes 300. If you convert that int to uint8, it overflows and you get effectively 300 % 256 = 44.

In Go, when you convert float64 directly to uint8, the same process happens implicitly and the expected output is uint8(44). GopherJS doesn't implement this behavior correctly and returns an incorrect uint8 value 300.

Probably affects most of float(32,64) -> (u,)int(8,16,32,64) conversions, not just float64->uint8.

https://play.golang.org/p/AmWeBRW2G0x
https://gopherjs.github.io/playground/#/2-nWgC-jIJ

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions