Steem Reputation Format Function in PHP

  • 时间:2020-09-08 11:08:55
  • 分类:网络文摘
  • 阅读:91 次

On Steem Blockchain, the reputation can be formatted in a logarithmetic (base 10) scale. Given recently, my PR to fix the reputation formatter in SteemJS is merged, I also translate this to PHP which I need.

1
2
3
4
5
6
7
8
9
function formatReputation($rep) {
    if (!$rep) return 25;
    $neg = $rep < 0;
    $rep = (string)$rep;
    $rep = $neg ? substr($rep, 1) : $rep;
    $v = log10(($rep > 0 ? $rep : -$rep) - 10) - 9;
    $v = $neg ? -$v : $v;
    return round($v * 9 + 25, 3);
}
function formatReputation($rep) {
    if (!$rep) return 25;
    $neg = $rep < 0;
    $rep = (string)$rep;
    $rep = $neg ? substr($rep, 1) : $rep;
    $v = log10(($rep > 0 ? $rep : -$rep) - 10) - 9;
    $v = $neg ? -$v : $v;
    return round($v * 9 + 25, 3);
}

Some Example usages:

1
2
3
4
5
6
echo formatReputation(95832978796820) . "\n";
echo formatReputation(10004392664120) . "\n";
echo formatReputation(30999525306309) . "\n";
echo formatReputation(-37765258368568) . "\n";
echo formatReputation(334486135407077) . "\n";
echo formatReputation(0) . "\n";
echo formatReputation(95832978796820) . "\n";
echo formatReputation(10004392664120) . "\n";
echo formatReputation(30999525306309) . "\n";
echo formatReputation(-37765258368568) . "\n";
echo formatReputation(334486135407077) . "\n";
echo formatReputation(0) . "\n";

The above PHP code should output the following values (you can use them to unit test the function):

69.834
61.002
65.422
-16.194
74.719
25
php Steem Reputation Format Function in PHP blockchain php SteemIt

php

–EOF (The Ultimate Computing & Technology Blog) —

推荐阅读:
a与b成反比例,b与c成反比例,a与c成什么比例?  如何计算玻璃瓶(啤酒瓶)的容积  齿轮齿数比的问题  哪些类型的网站不适合使用虚拟主机?  针对网站安全防护 探讨waf防火墙的作用  内容为王!百度搜索发布优质内容生产指南  搜狗SR值更新:好多网站SR值变1  SEO入门:三分钟带你了解权重  网站结构如何布局,会提高用户体验?  对于新站来说:如何让网站快速被搜索引擎收录呢? 
评论列表
添加评论