Atlas › Test

TestEncodeRoundsDown

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

Package
go.temporal.io/server/common/number
Suite / test hierarchy
TestCompact8Suite/TestEncodeRoundsDown
Test
TestEncodeRoundsDown
Introduced at
TestEncodeRoundsDown Frontier kind: Test frontier
Covered ranges
8
Covered lines
26
Covered files
1

Covered source

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

go.temporal.io/server/common/number/compact8.go 26 covered LOC · 8 ranges

Open complete file

19
20 // DecodeCompact8 converts a Compact8 value to an int64.
21 > func DecodeCompact8(b Compact8) int64 { compact8.go
22 > if b == 0 {
23 return 0
24 }
25 > e := int(b / 12) compact8.go
26 > m := int(b % 12)
27 > if e == 0 {
28 return int64(m) << (compact8offset + 1)
29 }
30 > return int64(12+m) << (e + compact8offset) compact8.go
31 }
32
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
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
60 }
61 > return Compact8(b) compact8.go
62 }
63