Skip to content

math.Signbit(-float64(0)) is false #2196

@gopherbot

Description

@gopherbot

by mikesamuel:

What steps will reproduce the problem?
1. In the Go playground enter the below and hit COMPILE & RUN

package main

import (
    "fmt"
    "math"
    )

func main() {
    fmt.Println(math.Copysign(0, -1))
}

2. See "-0" printed as expected
3. In the Go playground enter the below and hit COMPILE & RUN

package main

import "fmt"

func main() {
    z := float64(0)
    nz := -z
    fmt.Println(nz)
}
4. See "-0" printed
5. In the Go playground enter the below and hit COMPILE & RUN

package main

import "fmt"

func main() {
    nz := -float64(0)
    fmt.Println(nz)
}
6. See "0" printed

What is the expected output?

I expect all 3 programs to print "-0".


What do you see instead?

The first 2 print "-0" but the third prints "0".


Which compiler are you using (5g, 6g, 8g, gccgo)?

I tested using the playground, but can repeat this behavior on 6g.


Which operating system are you using?

Mac OS


Which revision are you using?  (hg identify)

5e1053337103+ tip

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