相关疑难解决方法(0)

golang中的负零字面值

IEEE754支持负零.但是这段代码

a  := -0.0
fmt.Println(a, 1/a)
Run Code Online (Sandbox Code Playgroud)

输出

0 +Inf
Run Code Online (Sandbox Code Playgroud)

我原以为预期的地方

-0 -Inf
Run Code Online (Sandbox Code Playgroud)

浮点格式基于IEEE754的其他语言允许您创建负零文字

Java:

float a = -0f;
System.out.printf("%f %f", a, 1/a); // outputs "-0,000000 -Infinity"
Run Code Online (Sandbox Code Playgroud)

C# :

var a = -0d;
Console.WriteLine(1/a); // outputs "-Infinity"
Run Code Online (Sandbox Code Playgroud)

Javascript:

?var a = -0;
console.log(a, 1/a);? // logs "0 -Infinity"
Run Code Online (Sandbox Code Playgroud)

但我在Go中找不到相同的东西.

你怎么写go负零文字?

math floating-point go ieee-754

9
推荐指数
2
解决办法
2677
查看次数

标签 统计

floating-point ×1

go ×1

ieee-754 ×1

math ×1