Skip to content

x/website: SumNumbers depends on map iteration order with float64 #51715

@niaow

Description

@niaow

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:

0 62.97 35.98 0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.website

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions