Skip to content

Commit f5de4ac

Browse files
authored
fix: adjust field alignment (#12)
1 parent c1fe20e commit f5de4ac

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

decimal.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ import (
1313
// currently support 12 precision, this is tunnable,
1414
// more precision => smaller maxInt
1515
// less precision => bigger maxInt
16-
const precision = 12
17-
const scale = 1e12
18-
const maxInt int64 = int64(math.MaxInt64) / scale
19-
const minInt int64 = int64(math.MinInt64) / scale
20-
const maxIntInFixed int64 = maxInt * scale
21-
const minIntInFixed int64 = minInt * scale
22-
const a1000InFixed int64 = 1000 * scale
23-
const aNeg1000InFixed int64 = -1000 * scale
24-
const aCentInFixed int64 = scale / 100
16+
const (
17+
precision = 12
18+
scale = 1e12
19+
maxInt int64 = int64(math.MaxInt64) / scale
20+
minInt int64 = int64(math.MinInt64) / scale
21+
maxIntInFixed int64 = maxInt * scale
22+
minIntInFixed int64 = minInt * scale
23+
a1000InFixed int64 = 1000 * scale
24+
aNeg1000InFixed int64 = -1000 * scale
25+
aCentInFixed int64 = scale / 100
26+
)
2527

2628
var pow10Table []int64 = []int64{
2729
1e0, 1e1, 1e2, 1e3, 1e4,
@@ -38,11 +40,15 @@ var pow10Table []int64 = []int64{
3840
// `valueCache[200000] = "1000"`
3941
//
4042
// this consumes about 9 MB in memory with pprof check.
41-
const cacheSize = 200001
42-
const cacheOffset = 100000
43+
const (
44+
cacheSize = 200001
45+
cacheOffset = 100000
46+
)
4347

44-
var valueCache [cacheSize]driver.Value
45-
var stringCache [cacheSize]string
48+
var (
49+
valueCache [cacheSize]driver.Value
50+
stringCache [cacheSize]string
51+
)
4652

4753
func init() {
4854
// init cache
@@ -62,10 +68,12 @@ func init() {
6268
// mostly due to lack of usage in Alpaca. we should be able to move "fallback" to "optimized" as needed.
6369

6470
// Variables
65-
var DivisionPrecision = decimal.DivisionPrecision
66-
var ExpMaxIterations = decimal.ExpMaxIterations
67-
var MarshalJSONWithoutQuotes = decimal.MarshalJSONWithoutQuotes
68-
var Zero = Decimal{fixed: 0}
71+
var (
72+
DivisionPrecision = decimal.DivisionPrecision
73+
ExpMaxIterations = decimal.ExpMaxIterations
74+
MarshalJSONWithoutQuotes = decimal.MarshalJSONWithoutQuotes
75+
Zero = Decimal{fixed: 0}
76+
)
6977

7078
func RescalePair(d1 Decimal, d2 Decimal) (Decimal, Decimal) {
7179
if d1.fallback == nil && d2.fallback == nil {
@@ -76,13 +84,13 @@ func RescalePair(d1 Decimal, d2 Decimal) (Decimal, Decimal) {
7684
}
7785

7886
type Decimal struct {
87+
// fallback to original decimal.Decimal if necessary
88+
fallback *decimal.Decimal
89+
7990
// represent decimal with 12 precision, 1.23 will have `fixed = 1_230_000_000_000`
8091
// max support decimal is 9_223_372.000_000_000_000
8192
// min support decimal is -9_223_372.000_000_000_000
8293
fixed int64
83-
84-
// fallback to original decimal.Decimal if necessary
85-
fallback *decimal.Decimal
8694
}
8795

8896
// optimized:

0 commit comments

Comments
 (0)