MCPcopy Create free account
hub / github.com/akyoto/q / SizeInt

Function SizeInt

src/cpu/SizeInt.go:6–22  ·  view source on GitHub ↗

SizeInt tells you how many bytes are needed to encode this signed number.

(number T)

Source from the content-addressed store, hash-verified

4
5// SizeInt tells you how many bytes are needed to encode this signed number.
6func SizeInt[T int | int8 | int16 | int32 | int64](number T) int {
7 x := int64(number)
8
9 switch {
10 case x >= math.MinInt8 && x <= math.MaxInt8:
11 return 1
12 case x >= math.MinInt16 && x <= math.MaxInt16:
13 return 2
14 case x >= math.MinInt32 && x <= math.MaxInt32:
15 return 4
16 default:
17 return 8
18 }
19}

Callers 10

CompileMethod · 0.92
TestSizeIntFunction · 0.92
MoveRegisterNumberSIFunction · 0.92
PushNumberFunction · 0.92
MoveRegisterNumberFunction · 0.92
memAccessFixedOffsetFunction · 0.92
memLoadExtendFunction · 0.92
encodeNumFunction · 0.92
canEncodeNumberMethod · 0.92
storeSpillNumberMethod · 0.92

Calls

no outgoing calls

Tested by 1

TestSizeIntFunction · 0.74