6
6
7
7
use TinyBlocks \Math \Internal \Exceptions \DivisionByZero ;
8
8
9
+ /**
10
+ * The BigNumber interface represents arbitrary-precision arithmetic, allowing
11
+ * precise mathematical operations on large or small numbers.
12
+ */
9
13
interface BigNumber
10
14
{
11
15
public const AUTOMATIC_SCALE = null ;
@@ -18,22 +22,6 @@ interface BigNumber
18
22
*/
19
23
public function add (BigNumber $ addend ): BigNumber ;
20
24
21
- /**
22
- * Subtracts another BigNumber (subtrahend) from the current BigNumber (minuend).
23
- *
24
- * @param BigNumber $subtrahend The BigNumber to be subtracted from the current BigNumber.
25
- * @return BigNumber A new BigNumber representing the difference between the two numbers.
26
- */
27
- public function subtract (BigNumber $ subtrahend ): BigNumber ;
28
-
29
- /**
30
- * Multiplies the current BigNumber (multiplicand) with another BigNumber (multiplier).
31
- *
32
- * @param BigNumber $multiplier The BigNumber to multiply the current BigNumber by.
33
- * @return BigNumber A new BigNumber representing the product of the two numbers.
34
- */
35
- public function multiply (BigNumber $ multiplier ): BigNumber ;
36
-
37
25
/**
38
26
* Divides the current BigNumber (dividend) by another BigNumber (divisor).
39
27
*
@@ -44,62 +32,64 @@ public function multiply(BigNumber $multiplier): BigNumber;
44
32
public function divide (BigNumber $ divisor ): BigNumber ;
45
33
46
34
/**
47
- * Returns a new BigNumber after applying the specified rounding mode .
35
+ * Retrieves the scale of the current BigNumber .
48
36
*
49
- * @param RoundingMode $mode The rounding mode to apply.
50
- * @return BigNumber A new BigNumber rounded according to the specified mode.
37
+ * @return int|null The scale of the current BigNumber, or null if no scale is applied.
51
38
*/
52
- public function withRounding ( RoundingMode $ mode ): BigNumber ;
39
+ public function getScale ( ): ? int ;
53
40
54
41
/**
55
- * Returns a new BigNumber with the specified scale .
42
+ * Compares the current BigNumber with another BigNumber to determine if it is greater .
56
43
*
57
- * @param int $scale The scale to apply to the BigNumber .
58
- * @return BigNumber A new BigNumber with the specified scale .
44
+ * @param BigNumber $other The BigNumber to compare with .
45
+ * @return bool True if the current BigNumber is greater than the other BigNumber, otherwise false .
59
46
*/
60
- public function withScale ( int $ scale ): BigNumber ;
47
+ public function isGreaterThan ( BigNumber $ other ): bool ;
61
48
62
49
/**
63
- * Returns a new BigNumber with the negated value of the current BigNumber .
50
+ * Compares the current BigNumber with another BigNumber to determine if it is greater than or equal .
64
51
*
65
- * @return BigNumber A new BigNumber representing the negated value of the current number.
52
+ * @param BigNumber $other The BigNumber to compare with.
53
+ * @return bool True if the current BigNumber is greater than or equal to the other BigNumber, otherwise false.
66
54
*/
67
- public function negate ( ): BigNumber ;
55
+ public function isGreaterThanOrEqual ( BigNumber $ other ): bool ;
68
56
69
57
/**
70
- * Retrieves the scale of the current BigNumber.
58
+ * Determines if the current BigNumber is negative .
71
59
*
72
- * @return int|null The scale of the current BigNumber, or null if no scale is applied .
60
+ * @return bool True if the BigNumber is negative, otherwise false .
73
61
*/
74
- public function getScale (): ? int ;
62
+ public function isNegative (): bool ;
75
63
76
64
/**
77
- * Determines if the current BigNumber is equal to zero.
65
+ * Determines if the current BigNumber is either negative or zero.
78
66
*
79
- * @return bool True if the BigNumber is zero, otherwise false.
67
+ * @return bool True if the BigNumber is negative or zero, otherwise false.
80
68
*/
81
- public function isZero (): bool ;
69
+ public function isNegativeOrZero (): bool ;
82
70
83
71
/**
84
- * Determines if the current BigNumber is negative .
72
+ * Compares the current BigNumber with another BigNumber to determine if it is less .
85
73
*
86
- * @return bool True if the BigNumber is negative, otherwise false.
74
+ * @param BigNumber $other The BigNumber to compare with.
75
+ * @return bool True if the current BigNumber is less than the other BigNumber, otherwise false.
87
76
*/
88
- public function isNegative ( ): bool ;
77
+ public function isLessThan ( BigNumber $ other ): bool ;
89
78
90
79
/**
91
- * Determines if the current BigNumber is positive .
80
+ * Compares the current BigNumber with another BigNumber to determine if it is less than or equal .
92
81
*
93
- * @return bool True if the BigNumber is positive, otherwise false.
82
+ * @param BigNumber $other The BigNumber to compare with.
83
+ * @return bool True if the current BigNumber is less than or equal to the other BigNumber, otherwise false.
94
84
*/
95
- public function isPositive ( ): bool ;
85
+ public function isLessThanOrEqual ( BigNumber $ other ): bool ;
96
86
97
87
/**
98
- * Determines if the current BigNumber is either negative or zero .
88
+ * Determines if the current BigNumber is positive .
99
89
*
100
- * @return bool True if the BigNumber is negative or zero , otherwise false.
90
+ * @return bool True if the BigNumber is positive , otherwise false.
101
91
*/
102
- public function isNegativeOrZero (): bool ;
92
+ public function isPositive (): bool ;
103
93
104
94
/**
105
95
* Determines if the current BigNumber is either positive or zero.
@@ -109,36 +99,34 @@ public function isNegativeOrZero(): bool;
109
99
public function isPositiveOrZero (): bool ;
110
100
111
101
/**
112
- * Compares the current BigNumber with another BigNumber to determine if it is less .
102
+ * Determines if the current BigNumber is equal to zero .
113
103
*
114
- * @param BigNumber $other The BigNumber to compare with.
115
- * @return bool True if the current BigNumber is less than the other BigNumber, otherwise false.
104
+ * @return bool True if the BigNumber is zero, otherwise false.
116
105
*/
117
- public function isLessThan ( BigNumber $ other ): bool ;
106
+ public function isZero ( ): bool ;
118
107
119
108
/**
120
- * Compares the current BigNumber with another BigNumber to determine if it is greater .
109
+ * Multiplies the current BigNumber (multiplicand) with another BigNumber (multiplier) .
121
110
*
122
- * @param BigNumber $other The BigNumber to compare with .
123
- * @return bool True if the current BigNumber is greater than the other BigNumber, otherwise false .
111
+ * @param BigNumber $multiplier The BigNumber to multiply the current BigNumber by .
112
+ * @return BigNumber A new BigNumber representing the product of the two numbers .
124
113
*/
125
- public function isGreaterThan (BigNumber $ other ): bool ;
114
+ public function multiply (BigNumber $ multiplier ): BigNumber ;
126
115
127
116
/**
128
- * Compares the current BigNumber with another BigNumber to determine if it is less than or equal .
117
+ * Returns a new BigNumber with the negated value of the current BigNumber .
129
118
*
130
- * @param BigNumber $other The BigNumber to compare with.
131
- * @return bool True if the current BigNumber is less than or equal to the other BigNumber, otherwise false.
119
+ * @return BigNumber A new BigNumber representing the negated value of the current number.
132
120
*/
133
- public function isLessThanOrEqual ( BigNumber $ other ): bool ;
121
+ public function negate ( ): BigNumber ;
134
122
135
123
/**
136
- * Compares the current BigNumber with another BigNumber to determine if it is greater than or equal .
124
+ * Subtracts another BigNumber (subtrahend) from the current BigNumber (minuend) .
137
125
*
138
- * @param BigNumber $other The BigNumber to compare with .
139
- * @return bool True if the current BigNumber is greater than or equal to the other BigNumber, otherwise false .
126
+ * @param BigNumber $subtrahend The BigNumber to be subtracted from the current BigNumber .
127
+ * @return BigNumber A new BigNumber representing the difference between the two numbers .
140
128
*/
141
- public function isGreaterThanOrEqual (BigNumber $ other ): bool ;
129
+ public function subtract (BigNumber $ subtrahend ): BigNumber ;
142
130
143
131
/**
144
132
* Converts the current BigNumber to a floating-point number.
@@ -154,4 +142,20 @@ public function toFloat(): float;
154
142
* @return string The string representation of the BigNumber.
155
143
*/
156
144
public function toString (): string ;
145
+
146
+ /**
147
+ * Returns a new BigNumber after applying the specified rounding mode.
148
+ *
149
+ * @param RoundingMode $mode The rounding mode to apply.
150
+ * @return BigNumber A new BigNumber rounded according to the specified mode.
151
+ */
152
+ public function withRounding (RoundingMode $ mode ): BigNumber ;
153
+
154
+ /**
155
+ * Returns a new BigNumber with the specified scale.
156
+ *
157
+ * @param int $scale The scale to apply to the BigNumber.
158
+ * @return BigNumber A new BigNumber with the specified scale.
159
+ */
160
+ public function withScale (int $ scale ): BigNumber ;
157
161
}
0 commit comments