1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
crateix!;
/**
| Compress amount.
|
| nAmount is of type uint64_t and thus
| cannot be negative. If you're passing
| in a CAmount (int64_t), make sure to
| properly handle the case where the amount
| is negative before calling CompressAmount(...).
|
| @pre Function defined only for 0 <=
| nAmount <= MAX_MONEY.
|
----------------------------
| Amount compression:
|
| - If the amount is 0, output 0
|
| - first, divide the amount (in base units) by
| the largest power of 10 possible; call the
| exponent e (e is max 9)
|
| - if e<9, the last digit of the resulting
| number cannot be 0; store it as d, and drop it
| (divide by 10)
| - call the result n
| - output 1 + 10*(9*n + d - 1) + e
|
| - if e==9, we only know the resulting number is
| not zero, so output 1 + 10*(n - 1) + 9 (this is
| decodable, as d is in [1-9] and e is in [0-9])
*/