package lastcall import "math/bits" const maxInt64 = uint64(1<<63 - 1) func mulDiv(a, b, c int64) int64 { if a < 0 || b < 0 || c <= 0 { panic("desk: math domain") } hi, lo := bits.Mul64(uint64(a), uint64(b)) if hi >= uint64(c) { panic("desk: math overflow") } q, _ := bits.Div64(hi, lo, uint64(c)) if q > maxInt64 { panic("desk: math overflow") } return int64(q) }