Author [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] Topic: problem about bit asset amount  (Read 569 times)

0 Members and 1 Guest are viewing this topic.

Offline alt

problem about bit asset amount
« on: March 05, 2014, 01:50:16 PM »

the data struct for amount of xts/bitasset is unit128
Code: [Select]
struct unit123{
      private:
          uint64_t hi;
          uint64_t lo;
  };
hi/lo has a limit with 2^64=18446744073709551616
here is the asset class
Code: [Select]
  asset::asset( float d, asset::type t )
  :unit(t)
  {
     amount = fc::uint128(double(d) * COIN,0);
  }
Code: [Select]
#define COIN                          (100000000ll)
so the amount has a limit about 2^64/COIN=184467440737
No problem to use this for amount of xfs, but It can't work with bitasset like bitusd.

Offline toast

Re: problem about bit asset amount
« Reply #1 on: March 05, 2014, 02:16:40 PM »
COIN should be per-asset, we don't need 8 digits of precision after the decimal point for BitUSD. If you think of it like shares 128 bits should always be high enough resolution... some assets will just have a larger smallest divisible unit
Do not use this post as information for making any important decisions. The only agreements I ever make are informal and non-binding. Take the same precautions as when dealing with a compromised account, scammer, sockpuppet, etc.

Offline alt

Re: problem about bit asset amount
« Reply #2 on: March 08, 2014, 01:52:34 PM »
some bugs are caused by this.
Code: [Select]
>>> short 184467440737usd
price (usd/bts): 184467440737
current balance: 33134.12286383 bts
required collateral: 10.00000000 bts
submit order? (y|n): y

>>> buy 184467440737usd
price per usd (ie: 1 usd): 0.00000001bts
current balance: 33134.12286383 bts
total price: 1844.67440736 bts
submit order? (y|n): y

>>> mine
Code: [Select]
>>> market bts usd
unspecified
overflow 10.00000000 bts * 184467440736.9999974400000 usd/bts
    {"a":"10.00000000 bts","p":"184467440736.9999974400000 usd/bts"}
    th_a  asset.cpp:269 operator*
type mismatch multiplying asset 10.00000000 bts by price 184467440736.9999974400000 usd/bts
    {"a":"10.00000000 bts","p":"184467440736.9999974400000 usd/bts"}
    th_a  asset.cpp:307 operator*

Code: [Select]
>>> buy 100usd
price per usd (ie: 1 usd): 0.01bts
current balance: 35634.12286383 bts
total price: 1.00000000 bts
submit order? (y|n): y
order submitted
>>> mine
unspecified
overflow 1.00000000 bts * 184467440736.9999974400000 usd/bts
    {"a":"1.00000000 bts","p":"184467440736.9999974400000 usd/bts"}
    th_a  asset.cpp:269 operator*
type mismatch multiplying asset 1.00000000 bts by price 184467440736.9999974400000 usd/bts
    {"a":"1.00000000 bts","p":"184467440736.9999974400000 usd/bts"}
    th_a  asset.cpp:307 operator*

    {"quote":"usd","base":"bts"}
    th_a  blockchain_db.cpp:756 match_orders

    {}
    th_a  blockchain_db.cpp:1149 match_orders
error generating new block
    {}
    th_a  blockchain_db.cpp:1319 generate_next_block

Offline alt

Re: problem about bit asset amount
« Reply #3 on: March 08, 2014, 01:57:23 PM »
COIN should be per-asset, we don't need 8 digits of precision after the decimal point for BitUSD. If you think of it like shares 128 bits should always be high enough resolution... some assets will just have a larger smallest divisible unit
I suggest just 2 digits after the decimal point for bitasset. so the limmit  for bitusd can up to  184467440737095516.

Offline alt

Re: problem about bit asset amount
« Reply #4 on: March 08, 2014, 02:20:34 PM »
Code: [Select]
>>> balance
36938.51500400 bts
184467440730.00000000 usd
0.00000000 btc
0.00000000 gld
....

>>> buy 18446744073usd
price per usd (ie: 1 usd): 0.00000001bts
current balance: 36938.51500400 bts
total price: 184.46744073 bts
submit order? (y|n): y
order submitted
>>> mine
>>> balance
36754.04741711 bts
unspecified
asset addition overflowed  184467440730.00000000 usd + 18446744073.00000000 usd = 18446744065.90448384 usd
    {"a":"184467440730.00000000 usd","b":"18446744073.00000000 usd","c":"18446744065.90448384 usd"}
    th_a  asset.cpp:124 operator+=

 

Google+