Negative zero literal in golang

﹥>﹥吖頭↗ 提交于 2019-12-05 03:44:10

There is a registered issue.

And it happens to give a kind of solution :

a := math.Copysign(0, -1)

It's not so bad as it obviously refers to the standard copysign function defined by IEEE754.

But this means you need to import a package and this still looks much too heavy for the (admittedly minor and rare) need.

package main

import (
        "fmt"
        "math"
)

func main() {
        a := 1. / math.Inf(-1)
        fmt.Println(a, 1/a)
}

(Also here)


Output:

-0 -Inf

I just tried out this and it seems to work for me .

package main

import (
    "fmt"
    )

func main() {
    zero := float64(0)
    neg_zero := -zero
    fmt.Println(zero, neg_zero)
}

Though it does not work as expected when I do neg_zer0 := - float64(0)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!