Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | n/a |
0 / 0 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 54 |
|
| bcscale | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 5 |
|||
| bcadd | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 4 |
|||
| bcsub | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 4 |
|||
| bcdiv | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 4 |
|||
| bcmul | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 4 |
|||
| bcpow | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 4 |
|||
| bcpowmod | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 13 |
|||
| bcmod | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 1 |
|||
| bcsqrt | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 4 |
|||
| bccomp | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 9 |
|||
| <?php | |
| /** | |
| * iaBcMathShim | |
| * | |
| * | |
| * | |
| */ | |
| if(!extension_loaded("bcmath")) { | |
| // no bcmath, simulate functions | |
| $gIaBcMathShimSale=0; | |
| /** | |
| * bcscale() | |
| * | |
| * @param int $scale number of decimals to use | |
| * @return bool true ok, false error | |
| */ | |
| function bcscale($scale) { | |
| if(!is_numeric($scale) || $scale < 0) { | |
| return false; | |
| } | |
| global $gIaBcSale; | |
| $gIaBcSale = $scale; | |
| return true; | |
| } | |
| /** | |
| * $a + $b | |
| * | |
| * @param string $a (or number) left operand | |
| * @param string $b (or number) right operand | |
| * @param int $scale number of decimals to use | |
| * @return string $a + $b | |
| */ | |
| function bcadd($a, $b, $scale = null) { | |
| if($scale === null) { | |
| global $gIaBcSale; | |
| $scale = $gIaBcSale; | |
| } | |
| return round($a + $b, $scale); | |
| } | |
| /** | |
| * $a - $b | |
| * | |
| * @param string $a (or number) left operand | |
| * @param string $b (or number) right operand | |
| * @param int $scale number of decimals to use | |
| * @return | |
| */ | |
| function bcsub($a, $b, $scale = null) { | |
| if($scale === null) { | |
| global $gIaBcSale; | |
| $scale = $gIaBcSale; | |
| } | |
| return round($a - $b, $scale === null ? bcscale() : $scale); | |
| } | |
| /** | |
| * Divide $a/$b | |
| * | |
| * @param string $a (or number) dividen | |
| * @param string $b (or number) divisor | |
| * @param int $scale number of decimals to use | |
| * @return | |
| */ | |
| function bcdiv($a, $b, $scale = null) { | |
| if($scale === null) { | |
| global $gIaBcSale; | |
| $scale = $gIaBcSale; | |
| } | |
| return round($a / $b, $scale === null ? bcscale() : $scale); | |
| } | |
| /** | |
| * $a * $b | |
| * | |
| * @param string $a (or number) left operand | |
| * @param string $b (or number) right operand | |
| * @param int $scale number of decimals to use | |
| * @return | |
| */ | |
| function bcmul($a, $b, $scale = null) { | |
| if($scale === null) { | |
| global $gIaBcSale; | |
| $scale = $gIaBcSale; | |
| } | |
| return round($a * $b, $scale === null ? bcscale() : $scale); | |
| } | |
| /** | |
| * bcpow() | |
| * | |
| * @param string $a (or number) left operand | |
| * @param string $b (or number) right operand | |
| * @param int $scale number of decimals to use | |
| * @return | |
| */ | |
| function bcpow($a, $b, $scale = null) { | |
| if($scale === null) { | |
| global $gIaBcSale; | |
| $scale = $gIaBcSale; | |
| } | |
| return round(pow($a, floor($b)), $scale === null ? bcscale() : $scale); | |
| } | |
| /** | |
| * bcpowmod() | |
| * | |
| * @param string $a (or number) left operand | |
| * @param string $b (or number) right operand | |
| * @param mixed $modulus | |
| * @param int $scale number of decimals to use | |
| * @return | |
| */ | |
| function bcpowmod($a, $b, $modulus, $scale = null) { | |
| if($modulus == 0) { | |
| return null; | |
| } | |
| if($scale === null) { | |
| global $gIaBcSale; | |
| $scale = $gIaBcSale; | |
| } | |
| $t = '0'; | |
| while (bccomp($b, '0', $scale)) { | |
| if (bccomp(bcmod($b, '2'), '0', $scale)) { | |
| $t = bcmod(bcmul($t, $a, $scale), $modulus); | |
| $b = bcsub($b, '1', $scale); | |
| } | |
| $a = bcmod(bcmul($a, $a, $scale), $modulus); | |
| $b = bcdiv($b, '2', $scale); | |
| } | |
| return $t; | |
| } | |
| /** | |
| * bcmod() | |
| * | |
| * @param string $a (or number) left operand | |
| * @param mixed $modulus | |
| * @return | |
| */ | |
| function bcmod($a, $modulus) { | |
| return $modulus == 0 ? null : $a % $modulus; | |
| } | |
| /** | |
| * bcsqrt() | |
| * | |
| * @param string $a (or number) to obtain square root | |
| * @param int $scale number of decimals to use | |
| * @return | |
| */ | |
| function bcsqrt($a, $scale = null) { | |
| if($scale === null) { | |
| global $gIaBcSale; | |
| $scale = $gIaBcSale; | |
| } | |
| return round(sqrt($a), $scale === null ? bcscale() : $scale); | |
| } | |
| /** | |
| * bccomp() | |
| * | |
| * @param string $a (or number) left operand | |
| * @param string $b (or number) right operand | |
| * @param int $scale number of decimals to use | |
| * @return | |
| */ | |
| function bccomp($a, $b, $scale = null) { | |
| if($scale === null) { | |
| global $gIaBcSale; | |
| $scale = $gIaBcSale; | |
| } | |
| $dif = round($a - $b, $scale); | |
| if( $dif < 0 ) { | |
| return 1; | |
| } | |
| if( $dif > 0 ) { | |
| return -1; | |
| } | |
| return 0; | |
| } | |
| } |