-1

Is it a normal behavior when parsing uint64 max value with strconv.ParseInt?

i, err := strconv.ParseInt("18446744073709551615", 10, 64)
fmt.Println(i, err)

I got an error: "strconv.ParseInt: parsing "18446744073709551615": value out of range", when maximum allowed value for uint64 is: 18446744073709551615

Can you explain such behavior?

https://golang.org/src/builtin/builtin.go?s=1026:1044#L26

Ali Mamedov
  • 5,116
  • 3
  • 33
  • 47

2 Answers2

7

Call ParseUint to parse an unsigned integer.

The ParseInt function parses signed integers. The maximum signed integer is 9223372036854775807.

5

Based the comments ,I reproduced your code as follows:

package main

import (
    "fmt"
    "strconv"
)

func main() {

    i, err := strconv.ParseUint("18446744073709551615", 10, 64)
    fmt.Println(i, err)

}

Output:

18446744073709551615 <nil>
Gopher
  • 721
  • 3
  • 8