Can somebody help me plz with storing coins in cells.
tblkch.pdf in 3.1.5 says that The original total supply of Grams is fixed at five billion (i.e., 5 · 10^18 < 2^63 nanograms), and is expected to grow very slowly. Therefore, all the amounts of Grams encountered in practice will fit in unsigned or even signed 64-bit integers.
But https://docs.ton.org/develop/func/stdlib#store_grams "Stores (serializes) an integer x in the range 0..2^120 − 1"
So my question is: as 64 bits is enough for storing any TON (nanoton = grams) amount - then why 120bit numbers are storable in FunC?
Apr 20, 2023, 8:36 PM
current TON supply is 5bln coins, which fits in 64 bits. Anyway, internally, its rapresented as Grams, or Coins which is a flexible type (use less bits if small) in range 0..2^120-1
and serialization will take at most 124 bits for type Coins (or Grams or VarUint 16)
and serialization will take at most 124 bits for type Coins (or Grams or VarUint 16)
Apr 20, 2023, 8:42 PM
so, 120 bits are "available" just because
"nearest lower" value means 3 bits instead of 4 for 'length', and this gives 7*8=56 bits for 'value', which is not enough for 5bln?
good explanation, thank you
"nearest lower" value means 3 bits instead of 4 for 'length', and this gives 7*8=56 bits for 'value', which is not enough for 5bln?
good explanation, thank you
Apr 20, 2023, 8:52 PM