Atlas › Test

TestEncodeKnownValues

Exact test identity: go.temporal.io/server/common/number/TestCompact8Suite/TestEncodeKnownValues

Package
go.temporal.io/server/common/number
Suite / test hierarchy
TestCompact8Suite/TestEncodeKnownValues
Test
TestEncodeKnownValues
Introduced at
compact8.go ×1 Frontier kind: Joint frontier
Covered ranges
11
Covered lines
30
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/number/compact8.go 30 covered LOC · 11 ranges

Open complete file

34 // The value is rounded down to the nearest representable value.
35 // Negative values go to 0 and values above the maximum representable go to 255.
36 > func EncodeCompact8(value int64) Compact8 { compact8.go
37 > if value <= 0 {
38 > return 0 compact8.go
39 > }
40
41 > uval := uint64(value) compact8.go
42 > bitLen := bits.Len64(uval)
43 >
44 > // Find shift such that uval >> shift is in [12, 23].
45 > // This extracts the significand for the normalized representation.
46 > shift := max(bitLen-5, 0)
47 > sig := int(uval >> uint(shift))
48 > if sig >= 24 {
49 > shift++
50 > sig = int(uval >> uint(shift))
51 > }
52
53 > e := shift - compact8offset compact8.go
54 >
55 > if e >= 1 {
56 > m := sig - 12 compact8.go
57 > b := e*12 + m
58 > if b > 255 {
59 > return 255 compact8.go
60 > }
61 > return Compact8(b) compact8.go
62 }
63
64 // Subnormal: value = m << (offset + 1), m in [1, 11]
65 > m := int(uval >> (compact8offset + 1)) compact8.go
66 > if m < 1 {
67 > return 0 compact8.go
68 > }
69 > if m > 11 { compact8.go
70 m = 11
71 }
72 > return Compact8(m) compact8.go
73 }
74