github.com/geraldss/go/src@v0.0.0-20210511222824-ac7d0ebfc235/runtime/internal/math/math.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package math 6 7 import "runtime/internal/sys" 8 9 const MaxUintptr = ^uintptr(0) 10 11 // MulUintptr returns a * b and whether the multiplication overflowed. 12 // On supported platforms this is an intrinsic lowered by the compiler. 13 func MulUintptr(a, b uintptr) (uintptr, bool) { 14 if a|b < 1<<(4*sys.PtrSize) || a == 0 { 15 return a * b, false 16 } 17 overflow := b > MaxUintptr/a 18 return a * b, overflow 19 }