// Copyright 2026 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.
// Package safemath contains overflow-safe math functions.
package safemathimport// Mul3 returns (x * y * z), unless at least one argument is negative or if the// computation overflows the int type.func (, , int) ( int, bool) {// The following is copied from image/geom.go in std, // but returns an explicit ok/not-ok rather than using -1 to indicate an error.if < 0 || < 0 || < 0 {return -1, false } , := bits.Mul64(uint64(), uint64())if != 0 {return -1, false } , = bits.Mul64(, uint64())if != 0 {return -1, false } := int()if < 0 || uint64() != {return -1, false }return , true}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.