I'm rewriting the amount class in beem for using fixed-point arithmetic

in #beem5 years ago (edited)

beem-logo

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
a = Amount(6.104, "STEEM")
print(a)
print(float(a))
print(a.amount)
print(a.symbol)
print(int(a))

will results in

6.104 STEEM
6.104
6.104
STEEM
6104

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.

What will change

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

What will change

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

What do you think?

Are my planed changes to the Amount class usefull? As the amount is a fixed point number, fixed point arithmetic should be applied, or?

Sort:  

Hi @holger80!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 7.375 which ranks you at #60 across all Steem accounts.
Your rank has not changed in the last three days.

In our last Algorithmic Curation Round, consisting of 188 contributions, your post is ranked at #2. Congratulations!

Evaluation of your UA score:
  • Your follower network is great!
  • The readers appreciate your great work!
  • Great user engagement! You rock!

Feel free to join our @steem-ua Discord server

This post has been just added as new item to timeline of beem on Steem Projects.

If you want to be notified about new updates from this project, register on Steem Projects and add beem to your favorite projects.

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

good morning @holger80. seems steemrewarding maybe down. is that why max vote delay is default at 9360 min. Will it eventually vote for accounts that are missed?

good morning, yes there was a small error in the script that blocked from streaming more blocks. It is fixed and steemrewarding is running again. Exacty, It will vote now all posted that were missed and for which the post age is below max vote delay.

ta i have just seen this thankyou

Hi, @holger80!

You just got a 3.28% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.