What version of Go are you using (go version)?
Go 1.18 via playground.
What did you do?
I added extreme float64 values to the input of the SumNumbers function from https://go.dev/doc/tutorial/generics.
https://go.dev/play/p/aQ1cotOVsEc
What did you expect to see?
The function returns the same value consistently.
What did you see instead?
Across 4 runs:
Re-running this may provide different results.
The function works correctly with int64 because integer addition is associative. Addition is not associative with float64 values, so the map order changes the result dramatically.
What version of Go are you using (
go version)?Go 1.18 via playground.
What did you do?
I added extreme float64 values to the input of the
SumNumbersfunction from https://go.dev/doc/tutorial/generics.https://go.dev/play/p/aQ1cotOVsEc
What did you expect to see?
The function returns the same value consistently.
What did you see instead?
Across 4 runs:
Re-running this may provide different results.
The function works correctly with
int64because integer addition is associative. Addition is not associative withfloat64values, so the map order changes the result dramatically.