Skip to content

strconv: Atoi documentation is slightly misleading #29461

@awulkan

Description

@awulkan

What version of Go are you using (go version)?

$ go version 1.11.4

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Irrelevant.

go env Output
$ go env

What did you do?

Look at the documentation here: https://golang.org/src/strconv/atoi.go?s=5013:5045#L192

What did you expect to see?

An explanation of strconv.Atoi that matched what it actually did.

What did you see instead?

An explanation that is only half true.

Atoi returns the result of ParseInt(s, 10, 0) converted to type int.

It appears that Atoi doesn't just return the value of ParseInt(s, 10, 0), it only calls ParseInt as a last alternative, the "slow path". Without checking the code I was under the belief that I could just replace Atoi with ParseInt and it would basically run the exact same code.

It appears that the documentation was correct up until this commit:
46aa9f5#diff-cbef0f4cdbfb7c355433bb342a5ef463

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions