Current SteemJs Library has a bug in computing the reputation. I have raised this two years ago and proposed a fix
Specifically:
1 | console.log(steem.formatter.reputation(10004392664120)); |
As you will see this output:
1 | 70 |
Which is incorrect. The problem is at the code L166
Here, the developer probably didn’t know the Math.log10
function can be used to compute the Log10, instead, he/she uses a math trick Math.log(x)/Math.log(10)
to compute the Math.log10 based on natural logarithm (base e ).
This will introduce rounding errors, and sometimes intermediate results will be amplified leading to much bigger errors.
1 | console.log(Math.log10(1000)) |
This will output
1 | 3 |
In Line 168, it uses parseInt
, therefore, the difference will be becoming ONE.
There are a few fixes:
- change
parseInt
toMath.round
- change entirely to use
Math.log10
- or completely rewriting this function, as my PR (approved by @ety001 thanks!, but not merged yet due to this is a legacy PR which was created more than 2 years ago and the main branch has differed a lot).
https://github.com/steemit/steem-js/pull/345/files
If you are happening to rely on this function, you probably need to do it yourself until this fix is merged.
Every little helps! I hope this helps!
Steem On!~
If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE
Alternatively, you could proxy to me if you are too lazy to vote!
Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy
Visit me at: https://steemyy.com
This page is synchronized from the post: ‘A Bug in the SteemJs Regarding the Incorrect Reputation’