blob: 13aee55b92ba172b5390e7f4f8ed379016883fd9 (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
package intconv
import (
"fmt"
"math"
)
// Uint32ToUint8 converts v to uint8, returning an error if it overflows.
func Uint32ToUint8(v uint32) (uint8, error) {
if v > math.MaxUint8 {
return 0, fmt.Errorf("intconv: uint32 %d overflows uint8", v)
}
return uint8(v), nil
}
|