/* A non-constant shift whose left operand is an untyped constant takes the type of the operand it is compared against, so `u == 1<<(n-1)` with u uint64 shifts at 64 bits. stage4 used to require the sibling's width to EQUAL the shift's own, so a 32-bit default shift stayed 32 bits against a uint64 sibling: 1<<61 evaluated to 0, `uint64(0) == 1<<61` was true, and `dfrac > 1<<(extra-1)` in strconv's ryu rounding was true for every exact value. That made stage4 format 1.0 as "2e+00" and 0.1 as "2.0001e-01" while legacy formatted them correctly, and it also moved ParseFloat's results. */ package main import ( "strconv" ) func main() { // Termination: a batch program must still be stoppable, so the entry // handles the channel the runtime closes on SIGINT/SIGTERM. select { case <-shutdown: return default: } var s uint32 = 62 var zero uint64 = 0 // Widening context: the shift must run at 64 bits. if zero == 1<<(s-1) { panic("uint64(0) == 1<<61; the shift ran at 32 bits") } if 1<<(s-1) == zero { panic("1<<61 == uint64(0); the shift ran at 32 bits") } var one uint64 = 1 if zero == one<<(s-1) { panic("uint64(0) == uint64(1)<<61") } half := uint64(1) << (s - 1) if half != 2305843009213693952 { panic("1<<61 != 2^61") } if zero == half { panic("uint64(0) == 1<<61 stored in a uint64") } // Signed 64-bit sibling. var izero int64 = 0 if izero == 1<<(s-2) { panic("int64(0) == 1<<60; the shift ran at 32 bits") } // Equal-width contexts keep working. var w uint32 = 4 if !(w == 1<<2) { panic("uint32(4) != 1<<2") } var b byte = 128 if !(b == 1<<7) { panic("byte(128) != 1<<7") } // The rounding that exposed it: exact values must not round up. if got := strconv.FormatFloat(1, 'e', 0, 64); got != "1e+00" { panic("FormatFloat(1, 'e', 0) = " | got) } if got := strconv.FormatFloat(1.5, 'e', 1, 64); got != "1.5e+00" { panic("FormatFloat(1.5, 'e', 1) = " | got) } if got := strconv.FormatFloat(0.1, 'e', 4, 64); got != "1.0000e-01" { panic("FormatFloat(0.1, 'e', 4) = " | got) } if got := strconv.FormatFloat(0.5, 'e', 0, 64); got != "5e-01" { panic("FormatFloat(0.5, 'e', 0) = " | got) } println("shift comparison context ok") }