1414 *
1515 * @package Nejcc\PhpDatatypes\Integers
1616 */
17- abstract class AbstractBigInteger implements BigIntegerInterface, NativeIntegerInterface
17+ abstract class AbstractBigInteger implements BigIntegerInterface
1818{
1919 use ArithmeticOperationsTrait;
2020 use IntegerComparisonTrait;
2121
22+ /**
23+ * @var string
24+ */
2225 protected readonly string $ value ;
2326
2427 public const MIN_VALUE = null ;
2528 public const MAX_VALUE = null ;
2629
30+ /**
31+ * @param int|string $value
32+ */
2733 public function __construct (int |string $ value )
2834 {
2935 $ this ->setValue ($ value );
3036 }
3137
38+ /**
39+ * @param int|string $value
40+ * @return void
41+ */
3242 protected function setValue (int |string $ value ): void
3343 {
3444 $ valueStr = (string )$ value ;
@@ -44,18 +54,30 @@ protected function setValue(int|string $value): void
4454 $ this ->value = $ valueStr ;
4555 }
4656
57+ /**
58+ * @return string
59+ */
4760 public function getValue (): string
4861 {
4962 return $ this ->value ;
5063 }
5164
52- // Implement comparison method
65+ /**
66+ * @param NativeIntegerInterface|BigIntegerInterface $other
67+ * @return int
68+ */
5369 public function compare (NativeIntegerInterface |BigIntegerInterface $ other ): int
5470 {
5571 return bccomp ($ this ->value , (string )$ other ->getValue ());
5672 }
5773
58- // Implement operation methods required by the trait
74+
75+ /**
76+ * @param BigIntegerInterface|NativeIntegerInterface $other
77+ * @param callable $operation
78+ * @param string $operationName
79+ * @return $this
80+ */
5981 protected function performOperation (
6082 BigIntegerInterface |NativeIntegerInterface $ other ,
6183 callable $ operation ,
@@ -71,21 +93,41 @@ protected function performOperation(
7193 return new static ($ result );
7294 }
7395
96+ /**
97+ * @param string $a
98+ * @param string $b
99+ * @return string
100+ */
74101 protected function addValues (string $ a , string $ b ): string
75102 {
76103 return bcadd ($ a , $ b , 0 );
77104 }
78105
106+ /**
107+ * @param string $a
108+ * @param string $b
109+ * @return string
110+ */
79111 protected function subtractValues (string $ a , string $ b ): string
80112 {
81113 return bcsub ($ a , $ b , 0 );
82114 }
83115
116+ /**
117+ * @param string $a
118+ * @param string $b
119+ * @return string
120+ */
84121 protected function multiplyValues (string $ a , string $ b ): string
85122 {
86123 return bcmul ($ a , $ b , 0 );
87124 }
88125
126+ /**
127+ * @param string $a
128+ * @param string $b
129+ * @return string
130+ */
89131 protected function divideValues (string $ a , string $ b ): string
90132 {
91133 if ($ b === '0 ' ) {
@@ -101,6 +143,11 @@ protected function divideValues(string $a, string $b): string
101143 return $ result ;
102144 }
103145
146+ /**
147+ * @param string $a
148+ * @param string $b
149+ * @return string
150+ */
104151 protected function modValues (string $ a , string $ b ): string
105152 {
106153 if ($ b === '0 ' ) {
0 commit comments