create account

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

View this thread on: hive.blogpeakd.comecency.com
· @holger80 · (edited)
$27.04
I'm rewriting the amount class in beem for using fixed-point arithmetic
<center>![beem-logo](https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo)</center>

I'm currently rewriting the Amount class of [beem](https://github.com/holgern/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?

πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 130 others
properties (23)
authorholger80
permlinki-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic
categorybeem
json_metadata"{"community": "busy", "app": "beempy/0.23.10", "format": "markdown", "tags": ["beem", "amount", "busy", "python", "steemdev"], "users": ["null"], "links": ["https://github.com/holgern/beem", "/@null"], "image": ["https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo"], "canonical_url": "https://hive.blog/beem/@holger80/i-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic"}"
created2019-04-06 21:36:03
last_update2020-05-23 14:29:54
depth0
children7
last_payout2019-04-13 21:36:03
cashout_time1969-12-31 23:59:59
total_payout_value21.614 HBD
curator_payout_value5.429 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,053
author_reputation358,857,509,568,825
root_title"I'm rewriting the amount class in beem for using fixed-point arithmetic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,598,740
net_rshares45,705,372,114,654
author_curate_reward""
vote details (194)
@michealb ·
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?
properties (22)
authormichealb
permlinkre-holger80-i-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic-20190407t004106233z
categorybeem
json_metadata{"tags":["beem"],"users":["holger80"],"app":"steemit/0.1"}
created2019-04-07 00:41:06
last_update2019-04-07 00:41:06
depth1
children2
last_payout2019-04-14 00:41:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length161
author_reputation50,653,248,582,155
root_title"I'm rewriting the amount class in beem for using fixed-point arithmetic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,606,526
net_rshares0
@holger80 ·
$0.28
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.
πŸ‘  
properties (23)
authorholger80
permlinkre-michealb-re-holger80-i-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic-20190407t060111873z
categorybeem
json_metadata{"tags":["beem"],"app":"steempeak/1.9.5"}
created2019-04-07 06:01:15
last_update2019-04-07 06:01:15
depth2
children1
last_payout2019-04-14 06:01:15
cashout_time1969-12-31 23:59:59
total_payout_value0.226 HBD
curator_payout_value0.052 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length251
author_reputation358,857,509,568,825
root_title"I'm rewriting the amount class in beem for using fixed-point arithmetic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,619,461
net_rshares478,332,134,474
author_curate_reward""
vote details (1)
@michealb ·
ta i have just seen this thankyou
properties (22)
authormichealb
permlinkre-holger80-re-michealb-re-holger80-i-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic-20190407t061129547z
categorybeem
json_metadata{"tags":["beem"],"app":"steemit/0.1"}
created2019-04-07 06:11:30
last_update2019-04-07 06:11:30
depth3
children0
last_payout2019-04-14 06:11:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length33
author_reputation50,653,248,582,155
root_title"I'm rewriting the amount class in beem for using fixed-point arithmetic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,619,656
net_rshares0
@partiko ·
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!
properties (22)
authorpartiko
permlinkre-i-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic-20190406t223019
categorybeem
json_metadata"{"app": "partiko"}"
created2019-04-06 22:30:21
last_update2019-04-06 22:30:21
depth1
children0
last_payout2019-04-13 22:30:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length213
author_reputation39,207,160,334,751
root_title"I'm rewriting the amount class in beem for using fixed-point arithmetic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,601,125
net_rshares0
@steem-plus ·
SteemPlus upvote
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](https://steemit.com/@steem-plus) to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
properties (22)
authorsteem-plus
permlinki-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic---vote-steemplus
categorybeem
json_metadata{}
created2019-04-07 12:47:54
last_update2019-04-07 12:47:54
depth1
children0
last_payout2019-04-14 12:47:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length435
author_reputation247,952,188,232,400
root_title"I'm rewriting the amount class in beem for using fixed-point arithmetic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,634,273
net_rshares0
@steem-ua ·
$0.03
#### 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](https://discord.gg/KpBNYGz)**
πŸ‘  
properties (23)
authorsteem-ua
permlinkre-i-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic-20190407t092737z
categorybeem
json_metadata"{"app": "beem/0.20.19"}"
created2019-04-07 09:27:36
last_update2019-04-07 09:27:36
depth1
children0
last_payout2019-04-14 09:27:36
cashout_time1969-12-31 23:59:59
total_payout_value0.019 HBD
curator_payout_value0.006 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length624
author_reputation23,214,230,978,060
root_title"I'm rewriting the amount class in beem for using fixed-point arithmetic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,627,135
net_rshares41,387,802,717
author_curate_reward""
vote details (1)
@steemprojects ·
This post has been just added as new item to _[timeline of beem on Steem Projects](https://steemprojects.com/projects/p/beem/?utm_source=comment_timeline&utm_medium=steem&utm_campaign=new_event&utm_content=c1)_.

If you want to be notified about new updates from this project, register on Steem Projects and add beem to your favorite projects.
πŸ‘  
properties (23)
authorsteemprojects
permlinkre-i-m-rewriting-the-amount-class-in-beem-for-using-fixed-point-arithmetic-20190406t221200
categorybeem
json_metadata""
created2019-04-06 22:12:03
last_update2019-04-06 22:12:03
depth1
children0
last_payout2019-04-13 22:12:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length345
author_reputation29,054,729,340
root_title"I'm rewriting the amount class in beem for using fixed-point arithmetic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,600,260
net_rshares151,793,671
author_curate_reward""
vote details (1)