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