I’m currently rewriting the Amount class of beem, my python library for steem. The amount class represents STEEM, SBD and VESTS amounts:
from beem.amount import Amount
will results in
Currently, a float number is internally used to
represent STEEM and SBD amounts. I’m trying to improve this by using the decimal class.
This changes may lead to different results in your code.
STEEM and SBD are fix point numbers, which means that they are basically integers.
6.104 STEEM can be represent as 6104. When I now divide or multiply, I could round the amount to an integer.
When I now divide the amount by 6, and multiply it again by 6, I will have the following operations:
int(int(6104 / 6) * 6)
which will be
int(1017 * 6) = 6102
Which has the meaning, we have 6.104 STEEM and want it divide by 6, so that 6 accounts can receive the same amount. As this is not possible, we need to send 0.002 STEEM first to @null and then it can be done.
In the same way, when I try to add 0.0001 to 6.104 STEEM, the amount will not change, no matter who often I add 0.0001 to 6.104 STEEM. As 0.0001 STEEM are not valid, it means basically that I try to add 0 STEEM to 6.104 STEEM. Thus, the amount will not change, no matter how often I try to add 0.0001.
int(6104 + 0.1) = 6104
The results of multiplication and addition may be different.
(6.104 STEEM + 0.0009) + 0.0009) = 6.104 STEEM
Before, the output of this equation was 6.105 STEEM
(6.104 STEEM / 6) * 6 = 6.102 STEEM
Before, the output was 6.104 STEEM
Are my planed changes to the Amount class usefull? As the amount is a fixed point number, fixed point arithmetic should be applied, or?