As a random exploration today, I was wondering if an LLM could figure out how to fix an integer overflow in some simple Go code. Here’s the prompt:
How can I print the value of “Big” in this program? As written, I get ./prog.go:19:14: cannot use Big (untyped int constant 1267650600228229401496703205376) as int value in argument to fmt.Println (overflows)
package main
import "fmt"
const (
Big = 1 << 100
)
func main() {
fmt.Println(Big)
}
Surprisingly, none of the LLMs I tried (including Claude Sonnet 3.5, GPT-4o, llama3-70b (Q4_0), and Gemini 1.5 Pro) were able to fix this issue on the first try; they all suggested solutions that still had the integer overflow. Eventually I coaxed most of them into a working solution, usually involving “math/big”, but even then there are lots of “math/big” solutions that don’t work (anything that involves converting Big
to a uint64 won’t work obviously), and many LLMs were quick to suggest them!