// Copyright 2025 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 strconvimport ()// Atoi64 parses an int64 from a string s.// The bool result reports whether s is a number// representable by a value of type int64.func ( string) (int64, bool) {if == "" {return0, false } := falseif [0] == '-' { = true = [1:] } := uint64(0)for := 0; < len(); ++ { := []if < '0' || > '9' {return0, false }if > math.MaxUint64/10 {// overflowreturn0, false } *= 10 := + uint64() - '0'if < {// overflowreturn0, false } = }if ! && > uint64(math.MaxInt64) {return0, false }if && > uint64(math.MaxInt64)+1 {return0, false } := int64()if { = - }return , true}// Atoi is like Atoi64 but for integers// that fit into an int.func ( string) (int, bool) {if , := Atoi64(); == int64(int()) {returnint(), }return0, false}// Atoi32 is like Atoi but for integers// that fit into an int32.func ( string) (int32, bool) {if , := Atoi64(); == int64(int32()) {returnint32(), }return0, false}
The pages are generated with Goldsv0.7.7-preview. (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.