Skip to content

cmd/compile: uint64(Float32bits(f)) on amd64 doesn't clear high bits #25322

@vishnulzr

Description

@vishnulzr

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

happens on GOOS="linux"

What did you do?

the high 32 bits of uint64(math.Float32bits(x)) are not zero

If possible, provide a recipe for reproducing the error.

package main

import (
	"fmt"
	"math"
)

func Foo(v float32) {
	fmt.Printf("%x\n", uint64(math.Float32bits(v)))
}

func main() {
	Foo(2.0)
}

this produces "c440000000"

What did you expect to see?

40000000

What did you see instead?

c40000000

The high order bits are not cleared in the cast to uint64

works fine in 1.9.6 and the generated code in 1.10.2 seems to optimize the cast out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions