Reputation: 1237
I'm attempting to calculate the square root of a Big Int in Go, but I'm not sure if I'm using the function correctly (or even the correct function).
Here is what I have so far:
package main
import (
"fmt"
"math/big"
)
func main() {
x := big.NewInt(10)
fmt.Print(x.ModSqrt(big.NewInt(2), big.NewInt(1)))
}
I am trying to calculate the square root of 10, but the output of this code is <nil>
.
Can someone please explain how to use this method correctly as I don't understand the documentation and I can't find any usages of this elsewhere that might help me understand how to use the method?
Upvotes: 0
Views: 585
Reputation: 281519
The big
package contains nothing for taking square roots. You'll have to implement it yourself. ModSqrt
, in particular, is useless to you; it's a modular arithmetic thing.
Upvotes: 2