Atlas › Test

TestRoundDown

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

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

Covered source

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

go.temporal.io/server/common/number/compact8.go 36 covered LOC · 14 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 compact8.go
24 > }
25 > e := int(b / 12) compact8.go
26 > m := int(b % 12)
27 > if e == 0 {
28 > return int64(m) << (compact8offset + 1) compact8.go
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
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