// Untyped constant promotion: an integer operand against a float operand is a // float operation. // // stage4's SSA-builder constant fold took the LEFT operand's type, so // `1/2.0` folded to the int constant 0 (and `var x float64 = 1/2.0` to 0.0) // while the same expression in a `const` declaration folded correctly. That // also truncated `1/Ln2`, the basis of math.Log2, and math.Log2 sizes the // buffer in math/big's base-10 conversion - so `big.Int.String` lost its // leading digits. The non-fold path already applied the promotion rule. package main import "math" func main() { if 1/2.0 != 0.5 { panic("1/2.0") } if 7/2.0 != 3.5 { panic("7/2.0") } if 1/4.0 != 0.25 { panic("1/4.0") } if 1/2.5 != 0.4 { panic("1/2.5") } if 1.0/2 != 0.5 { panic("1.0/2") } if 2*0.5 != 1.0 { panic("2*0.5") } if 1+0.5 != 1.5 { panic("1+0.5") } if 1-0.5 != 0.5 { panic("1-0.5") } if 1/math.Ln2 < 1.442695 || 1/math.Ln2 > 1.442696 { panic("1/Ln2") } l2 := math.Log2(10) if l2 < 3.321928 || l2 > 3.321929 { panic("Log2(10)") } println("ok") }