MCPcopy
hub / github.com/canopy-network/canopy / SafeMulDiv

Function SafeMulDiv

lib/util.go:988–1000  ·  view source on GitHub ↗

SafeMulDiv computes (a * b) / c safely using big.Int.

(a, b, c uint64)

Source from the content-addressed store, hash-verified

986
987// SafeMulDiv computes (a * b) / c safely using big.Int.
988func SafeMulDiv(a, b, c uint64) uint64 {
989 if c == 0 {
990 return 0
991 }
992 bigA := new(big.Int).SetUint64(a)
993 bigB := new(big.Int).SetUint64(b)
994 bigC := new(big.Int).SetUint64(c)
995
996 num := new(big.Int).Mul(bigA, bigB)
997 res := new(big.Int).Div(num, bigC)
998
999 return res.Uint64()
1000}
1001
1002// IntSqrt returns the integer square root of n (truncated)
1003func IntSqrt(n uint64) uint64 {

Callers 3

HandleBatchWithdrawMethod · 0.92
HandleBatchDepositMethod · 0.92
deliverRemoteReceiptsFunction · 0.92

Calls 1

SetUint64Method · 0.65

Tested by 1

deliverRemoteReceiptsFunction · 0.74