Skip to content

Commit 426b211

Browse files
committed
feat: type/number: add Itou16()
1 parent 30141db commit 426b211

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

type/number/numconv.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ func Itou(i int) (uint, error) {
4242
}
4343
}
4444

45+
func Itou16(i int) (uint16, error) {
46+
if i < 0 || i > int(^uint16(0)) {
47+
return 0, errorsutil.Wrapf(ErrOverflow, "int is out of range for uint16 (%d)", i)
48+
} else {
49+
return uint16(i), nil
50+
}
51+
}
52+
4553
func Itou32(i int) (uint32, error) {
4654
if i < 0 || i > int(^uint32(0)) {
4755
return 0, errorsutil.Wrapf(ErrOverflow, "int is out of range for uint32 (%d)", i)

0 commit comments

Comments
 (0)