func ParseInt(s string, base int, bitSize int) (i int64, err error)

ParseInt always returns int64.

bitSize defines the range of values.

If the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange.

http://golang.org/pkg/strconv/#ParseInt

type int int

int is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, int32.

http://golang.org/pkg/builtin/#int

So int could be bigger than 32 bit in the future or on some systems like int in C.

I guess on some systems int64 might be faster than int32 because that system only works with 64-bit integers.

Here is an example of an error when bitSize is 8:

http://play.golang.org/p/_osjMqL6Nj

package main

import (
    "fmt"
    "strconv"
)

func main() {
    i, err := strconv.ParseInt("123456", 10, 8)
    fmt.Println(i, err)
}
Answer from Shuriken on Stack Overflow
🌐
GitHub
github.com › google › go-cmp › issues › 286
How to compare int to int64? · Issue #286 · google/go-cmp
January 5, 2022 - package main import ( "fmt" "github.com/google/go-cmp/cmp" ) func main() { fmt.Print(cmp.Diff( map[string]interface{}{"a": 1, "b": 2, "c": int64(3)}, map[string]interface{}{"a": int64(1), "b": 2, "c": int64(3)}, cmp.Transformer("intToInt64", func(i int) int64 { return int64(i) }), )) }
Author   pofl
Top answer
1 of 6
78
func ParseInt(s string, base int, bitSize int) (i int64, err error)

ParseInt always returns int64.

bitSize defines the range of values.

If the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange.

http://golang.org/pkg/strconv/#ParseInt

type int int

int is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, int32.

http://golang.org/pkg/builtin/#int

So int could be bigger than 32 bit in the future or on some systems like int in C.

I guess on some systems int64 might be faster than int32 because that system only works with 64-bit integers.

Here is an example of an error when bitSize is 8:

http://play.golang.org/p/_osjMqL6Nj

package main

import (
    "fmt"
    "strconv"
)

func main() {
    i, err := strconv.ParseInt("123456", 10, 8)
    fmt.Println(i, err)
}
2 of 6
36

Package strconv

func ParseInt

func ParseInt(s string, base int, bitSize int) (i int64, err error)

ParseInt interprets a string s in the given base (2 to 36) and returns the corresponding value i. If base == 0, the base is implied by the string's prefix: base 16 for "0x", base 8 for "0", and base 10 otherwise.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64.

The errors that ParseInt returns have concrete type *NumError and include err.Num = s. If s is empty or contains invalid digits, err.Err = ErrSyntax; if the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange.

ParseInt always returns an int64 value. Depending on bitSize, this value will fit into int, int8, int16, int32, or int64. If the value cannot be represented by a signed integer of the size given by bitSize, then err.Err = ErrRange.

The Go Programming Language Specification

Numeric types

The value of an n-bit integer is n bits wide and represented using two's complement arithmetic.

int8        the set of all signed  8-bit integers (-128 to 127)
int16       the set of all signed 16-bit integers (-32768 to 32767)
int32       the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64       the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

There is also a set of predeclared numeric types with implementation-specific sizes:

uint     either 32 or 64 bits
int      same size as uint

int is either 32 or 64 bits, depending on the implementation. Usually it's 32 bits for 32-bit compilers and 64 bits for 64-bit compilers.

To find out the size of an int or uint, use strconv.IntSize.

Package strconv

Constants

const IntSize = intSize

IntSize is the size in bits of an int or uint value.

For example,

package main

import (
    "fmt"
    "runtime"
    "strconv"
)

func main() {
    fmt.Println(runtime.Compiler, runtime.GOARCH, runtime.GOOS)
    fmt.Println(strconv.IntSize)
}

Output:

gc amd64 linux
64
Discussions

Is a Int the same as Int64?
What does the Go documentation say? More on reddit.com
🌐 r/golang
15
0
March 24, 2022
go - interface & integer comparison in golang - Stack Overflow
A value x of non-interface type X and a value t of interface type T are comparable when values of type X are comparable and X implements T. They are equal if t's dynamic type is identical to X and t's dynamic value is equal to x. ... Sign up to request clarification or add additional context in comments. ... Why can you use type assertion such as i.(uint64) == 0? Does the compiler assume 0 is a uint64 too? play.golang... More on stackoverflow.com
🌐 stackoverflow.com
go - Golang compare numbers - Stack Overflow
Ideally, I just want to cast them to int64 or float64, but if they are int or float, I have no way to find them until exhausted all possible types. ... In the more general case (i.e. outside of JSON) you could just create a type switch - golang.org/doc/effective_go.html#type_switch - and only ... More on stackoverflow.com
🌐 stackoverflow.com
Compare two variables regardless of their data type
Hi, I am trying to compare only the value of a variable regardless of its data type. I don’t want to do the typical “switch case” where I make the assertion for each type that exists. Is it possible to do this? compare 2 variables regardless of their data type? package main import ( "fmt" ... More on forum.golangbridge.org
🌐 forum.golangbridge.org
1
0
June 19, 2020
🌐
YourBasic
yourbasic.org › golang › int-vs-int64
Pick the right one: int vs. int64 · YourBasic Go
An int64 is the typical choice when memory isn’t an issue. In particular, you can use a byte, which is an alias for uint8, to be extra clear about your intent. Similarly, you can use a rune, which is an alias for int32, to emphasize than an integer represents a code point. Sometimes it makes little or no difference if you use 32 or 64 bits for data, and then it’s quite common to simply use an int.
🌐
Reddit
reddit.com › r/golang › is a int the same as int64?
Is a Int the same as Int64? : r/golang
March 24, 2022 - An int is 32 bits on a 32 bit machine and 64 bits on a 64 bit machines. An int64 is obviously always 64 bits. But you can't assign an int to an int64 or vice versa because they're different types.
🌐
Google Groups
groups.google.com › g › golang-nuts › c › 3rH1e4wnFR8
int or int64
I'd say just use int for array indices and such. It should always be enough, since in 32 bit systems you can't address more than 4GB of bytes, which implies that you'll have arrays and lists shorter than 4GB, which means that normal int is sufficient.
🌐
Programming.Guide
programming.guide › go › int-vs-int64.html
Go: int vs. int64 | Programming.Guide
// A Duration represents the elapsed time between two instants // as an int64 nanosecond count. The representation limits the // largest representable duration to approximately 290 years. type Duration int64 · What's the maximum value of an int? shows how to compute the size and limit values of an int as untyped constants.
Find elsewhere
🌐
DEV Community
dev.to › herocod3r › demystifying-the-int-type-in-go-1f63
Demystifying the int type in Go - DEV Community
May 3, 2021 - func printAll(){ fmt.Printf(" int %d,\n int8 %d, \n int16 %d,\n int32 %d, \n int64 %d", unsafe.Sizeof(int(0)), unsafe.Sizeof(int8(0)), unsafe.Sizeof(int16(0)), unsafe.Sizeof(int32(0)), unsafe.Sizeof(int64(0))) }
🌐
Medium
medium.com › learning-the-go-programming-language › comparing-values-in-go-8f7b002e767a
Comparing Values in Go. Once again, I started my Sunday… | by Vladimir Vivien | Learning the Go Programming Language | Medium
May 1, 2017 - Due to Go’s strict type adherence however, integers can only be compared with other integers and floating point values can only be compared with other floating point values (or expression that produce them).
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › how to change int to int64 in golang? [solved]
How to change int to int64 in Golang? [SOLVED] | GoLinuxCloud
January 8, 2023 - The conversion between int and int64 is called type conversion. In the example below, we will try to convert an int to int64. We can use the fmt.Printf function with the %T verb to print out the type of the variable: ... package main import ...
🌐
Google Groups
groups.google.com › g › golang-nuts › c › tIZToSTuEj4
Comparison in numeric types from interface
October 8, 2011 - On Oct 8, 6:45 pm, Archos ... at least 3 different kinds to > hold both minimum and maximum values --uint64, int64, float64--. If you choose float64 it may be able to cover all *integer* values that the program ever encounters during its run-time....
🌐
Reddit
reddit.com › r/golang › int64 vs int | adding in golang
r/golang on Reddit: int64 vs int | Adding in GoLang
March 9, 2018 -

So I am sorry if this is the wrong subreddit to be posting this but I ran into an unusual error today that I wasn't able to come up with a solution for... I have a string being parsed to an int via strconv.ParseInt which returns an int64, but once I have the int64 I cannot seem to add other numbers to it. Is there something I am missing?

stringVal := "1" 
valInt1, errValInt1 := strconv.ParseInt(stringVal, 0 , 64)
currentVal := valInt1
newVal := currentVal + 1

Thank you for any advice or help.

Edit: Thanks everyone... outside of this I was casting it back to string to place it in a cache... looks like you can't use string(int64) for int64s but rather need to use strconv.FormatInt()

🌐
Go Packages
pkg.go.dev › math › big
big package - math/big - Go Packages
The result is Exact if x.IsInt(); otherwise it is Below for x > 0, and Above for x < 0. If a non-nil *Int argument z is provided, Int stores the result in z instead of allocating a new Int. ... Int64 returns the integer resulting from truncating x towards zero.