Getting different output when casting between int and int64 in Go; is it due to processor architecture? -


a small part of application i'm using test expected behavior giving different output, depending on processor run on. here's relevant part of code:

   b := 0; b < intcounter; b++ {              //int64random = rand.int63()             int64random = int64(rand.int())  //checking sanity fmt.println("int64random " + strconv.formatint(int64random, 10))              slctestnums = append(slctestnums, int64random)     } 

when run on mac (amd64, darwin) output like:

int64random 2991558990735723489 int64random 7893058381743103687 int64random 7672635040537837613 int64random 1557718564618710869 int64random 2107352926413218802 

when run on pi (arm, linux) output like:

int64random 1251459732 int64random 1316852782 int64random 971786136 int64random 1359359453 int64random 729066469 

if on pi change int64random = rand.int63() , recompile, output like:

int64random 7160249008355881289 int64random 7184347289772016444 int64random 9201664581141930074 int64random 917219239600463359 int64random 6015348270214295654 

...which more closely matches mac getting. because of changed @ runtime due processor architecture? why int64(rand.int()) generating int64-ranged numbers instead of keeping int-ranged number, changing type variable it's being stored in? missing go documentation mentions behavior?

according https://golang.org/doc/go1.1

the language allows implementation choose whether int type , uint types 32 or 64 bits. previous go implementations made int , uint 32 bits on systems. both gc , gccgo implementations make int , uint 64 bits on 64-bit platforms such amd64/x86-64

rand.int() returns int. on amd64 64 bits, on arm 32 bits


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -