<分区>
在下面的 go 代码片段中,我很难理解为什么结果不同:
func main() {
a := -0.2; b := -0.1;
fmt.Println(a+b)
//Outputs expected float value with rounding error : -0.30000000000000004
c := (-0.2)+(-0.1)
fmt.Println(c)
//Will ouput -0.3 (the actual exact constant).
}
究竟发生了什么,当这些常量不用于实例化 float 时,go 是否以某种方式将 c 操作作为常量而不是 float64 操作执行? 完整工作版本:https://play.golang.org/p/kUICDGFiMvf
如有任何见解,我们将不胜感激。