MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / Inverse

Function Inverse

math/modular/inverse.go:21–28  ·  view source on GitHub ↗

Inverse Modular function

(a, m int64)

Source from the content-addressed store, hash-verified

19
20// Inverse Modular function
21func Inverse(a, m int64) (int64, error) {
22 gcd, x, _ := gcd.Extended(a, m)
23 if gcd != 1 || m == 0 {
24 return 0, ErrorInverse
25 }
26
27 return ((m + (x % m)) % m), nil // this is necessary because of Go's use of architecture specific instruction for the % operator.
28}

Callers 3

NewFunction · 0.92
testPreconditionFunction · 0.92
TestInverseFunction · 0.85

Calls 1

ExtendedFunction · 0.92

Tested by 2

testPreconditionFunction · 0.74
TestInverseFunction · 0.68