1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Samsara\Fermat\Provider;
|
4
|
|
|
|
5
|
|
|
class ArithmeticProvider
|
6
|
|
|
{
|
7
|
|
|
|
8
|
|
|
public static function add($number1, $number2)
|
9
|
|
|
{
|
10
|
|
|
return bcadd($number1, $number2);
|
11
|
|
|
}
|
12
|
|
|
|
13
|
|
|
public static function subtract($left, $right)
|
14
|
|
|
{
|
15
|
|
|
return bcsub($left, $right);
|
16
|
|
|
}
|
17
|
|
|
|
18
|
|
|
public static function multiply($number1, $number2)
|
19
|
|
|
{
|
20
|
|
|
return bcmul($number1, $number2);
|
21
|
|
|
}
|
22
|
|
|
|
23
|
|
|
public static function divide($numerator, $denominator, $precision = null)
|
24
|
|
|
{
|
25
|
|
|
return bcdiv($numerator, $denominator, $precision);
|
26
|
|
|
}
|
27
|
|
|
|
28
|
|
|
public static function pow($base, $exponent)
|
29
|
|
|
{
|
30
|
|
|
return bcpow($base, $exponent);
|
31
|
|
|
}
|
32
|
|
|
|
33
|
|
|
public static function squareRoot($number, $precision = null)
|
34
|
|
|
{
|
35
|
|
|
return bcsqrt($number, $precision);
|
36
|
|
|
}
|
37
|
|
|
|
38
|
|
|
public static function modulo($number, $modulo)
|
39
|
|
|
{
|
40
|
|
|
return bcmod($number, $modulo);
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
public static function compare($left, $right, $scale = null)
|
44
|
|
|
{
|
45
|
|
|
return bccomp($left, $right, $scale);
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
public static function powmod($left, $right, $modulus, $scale = null)
|
49
|
|
|
{
|
50
|
|
|
return bcpowmod($left, $right, $modulus, $scale);
|
51
|
|
|
}
|
52
|
|
|
|
53
|
|
|
public static function factorial($number)
|
54
|
|
|
{
|
55
|
|
|
for ($x = 1; $number > 0; $number--) {
|
56
|
|
|
$x = bcmul($x, $number);
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
return $x;
|
60
|
|
|
}
|
61
|
|
|
|
62
|
|
|
} |