Atlas › Test
TestRoundtrip
Exact test identity: go.temporal.io/server/common/number/TestCompact8Suite/TestRoundtrip
- Package
go.temporal.io/server/common/number
- Suite / test hierarchy
TestCompact8Suite/TestRoundtrip
- Test
TestRoundtrip
- Introduced at
- TestRoundtrip 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 {
24
>
}
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 {
39
>
}
40
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
54
>
55
>
if e >= 1 {
57
>
b := e*12 + m
58
>
if b > 255 {
59
return 255
60
}
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
68
}
70
m = 11
71
}
73
}
74