View documentation - http://golang.org/pkg/math/big/
Mod sets z to the module x% y for y! = 0 and returns z. If y == 0, panic occurs with division by zero. Mod implements the Euclidean module (as opposed to Go); see the DivMod section for more details.
10% 4 = 2, but I get 8 with this (using math / big package to do the same) - http://play.golang.org/p/_86etDvLYq
package main
import "fmt"
import "math/big"
import "strconv"
func main() {
ten := new(big.Int)
ten.SetBytes([]byte(strconv.Itoa(10)))
four := new(big.Int)
four.SetBytes([]byte(strconv.Itoa(4)))
tenmodfour := new(big.Int)
tenmodfour = tenmodfour.Mod(ten, four)
fmt.Println("mod", tenmodfour)
}
I most likely had something wrong. Where is the mistake?
source
share