he may not know how to read assembler:
the question is - yes, its optimized or even directly evaluated.
here is an example:
func main() {
x := 10+rand.Intn(10)
for i := 1; i <= int(math.Sqrt(float64(x))); i++ {
fmt.Println(i)
}
}
which produces these relevant bits and pieces:
movl $1, CX
jmp main_pc193
main_pc79:
(....)
main_pc193:
xorps X0, X0 // x0 := 0
cvtsq2SD AX, X0 // x0 = float(int(ax))
sqrtsd X0, X0 // x0 = sqrt(x0)
cvttsd2SQ X0, DX
cmpq CX, DX
jle main_pc79
so, the answer is - sqrt is calculated every iteration, so you better assign that to a variable outside the loop!