PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / Brick / Math / Internal / Calculator / BcMathCalculator.php

BcMathCalculator.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/Brick/Math/Internal/Calculator/BcMathCalculator.php

117 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace WP_DEFENDER_VENDOR\Brick\Math\Internal\Calculator;
6
7 use WP_DEFENDER_VENDOR\Brick\Math\Internal\Calculator;
8
9 /**
10 * Calculator implementation built around the bcmath library.
11 *
12 * @internal
13 *
14 * @psalm-immutable
15 */
16 class BcMathCalculator extends Calculator
17 {
18 /**
19 * {@inheritdoc}
20 */
21 public function add(string $a, string $b) : string
22 {
23 return \bcadd($a, $b, 0);
24 }
25
26 /**
27 * {@inheritdoc}
28 */
29 public function sub(string $a, string $b) : string
30 {
31 return \bcsub($a, $b, 0);
32 }
33
34 /**
35 * {@inheritdoc}
36 */
37 public function mul(string $a, string $b) : string
38 {
39 return \bcmul($a, $b, 0);
40 }
41
42 /**
43 * {@inheritdoc}
44 *
45 * @psalm-suppress InvalidNullableReturnType
46 * @psalm-suppress NullableReturnStatement
47 */
48 public function divQ(string $a, string $b) : string
49 {
50 return \bcdiv($a, $b, 0);
51 }
52
53 /**
54 * {@inheritdoc}
55 *
56 * @psalm-suppress InvalidNullableReturnType
57 * @psalm-suppress NullableReturnStatement
58 */
59 public function divR(string $a, string $b) : string
60 {
61 if (version_compare(PHP_VERSION, '7.2') >= 0) {
62 return \bcmod($a, $b, 0);
63 }
64
65 return \bcmod($a, $b);
66 }
67
68 /**
69 * {@inheritdoc}
70 */
71 public function divQR(string $a, string $b) : array
72 {
73 $q = \bcdiv($a, $b, 0);
74
75 if (version_compare(PHP_VERSION, '7.2') >= 0) {
76 $r = \bcmod($a, $b, 0);
77 } else {
78 $r = \bcmod($a, $b);
79 }
80
81 assert($q !== null);
82 assert($r !== null);
83
84 return [$q, $r];
85 }
86
87 /**
88 * {@inheritdoc}
89 */
90 public function pow(string $a, int $e) : string
91 {
92 return \bcpow($a, (string) $e, 0);
93 }
94
95 /**
96 * {@inheritdoc}
97 *
98 * @psalm-suppress InvalidNullableReturnType
99 * @psalm-suppress NullableReturnStatement
100 */
101 public function modPow(string $base, string $exp, string $mod) : string
102 {
103 return \bcpowmod($base, $exp, $mod, 0);
104 }
105
106 /**
107 * {@inheritDoc}
108 *
109 * @psalm-suppress NullableReturnStatement
110 * @psalm-suppress InvalidNullableReturnType
111 */
112 public function sqrt(string $n) : string
113 {
114 return \bcsqrt($n, 0);
115 }
116 }
117