Closed
Description
import (
"fmt"
"math/big"
)
func main() {
A := new(big.Int)
B := new(big.Int)
P := new(big.Int)
C := new(big.Int)
A.SetUint64(0xAAAAAAAA00000000)
B.SetUint64(0xAAAAAAAA00000000)
P.SetUint64(0xFFFFFFFF00000001)
C.Exp(A, B, P)
fmt.Printf("0x%x ** 0x%x %% 0x%x = 0x%x\n", A, B, P, C)
}I get different results whether I run it in amd64 mode or 386 mode
$ go run exptest.go
0xaaaaaaaa00000000 ** 0xaaaaaaaa00000000 % 0xffffffff00000001 = 0x1
$ GOARCH=386 go run exptest.go
0xaaaaaaaa00000000 ** 0xaaaaaaaa00000000 % 0xffffffff00000001 = 0xc1540908df2582c2
The first one is correct (you can verify this with python thus)
$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> pow(0xAAAAAAAA00000000 , 0xAAAAAAAA00000000 , 0xFFFFFFFF00000001)
1L
The playground also gives the incorrect results.
Tested with go 1.5.1 and tip
go version devel +b2963a5 Sun Dec 6 06:28:33 2015 +0000 linux/amd64
go version go1.5.1 linux/amd64