forked from moneyphp/money
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.php
152 lines (138 loc) · 3.66 KB
/
Calculator.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
<?php
declare(strict_types=1);
namespace Money;
use Money\Exception\InvalidArgumentException;
/**
* Money calculations abstracted away from the Money value object.
*
* @internal the calculator component is an internal detail of this library: it is only supposed to be replaced if
* your system requires a custom architecture for operating on large numbers.
*/
interface Calculator
{
/**
* Compare a to b.
*
* Retrieves a negative value if $a < $b.
* Retrieves a positive value if $a > $b.
* Retrieves zero if $a == $b
*
* @psalm-param numeric-string $a
* @psalm-param numeric-string $b
*
* @psalm-pure
*/
public static function compare(string $a, string $b): int;
/**
* Add added to amount.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $addend
*
* @psalm-return numeric-string
*
* @psalm-pure
*/
public static function add(string $amount, string $addend): string;
/**
* Subtract subtrahend from amount.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $subtrahend
*
* @psalm-return numeric-string
*
* @psalm-pure
*/
public static function subtract(string $amount, string $subtrahend): string;
/**
* Multiply amount with multiplier.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $multiplier
*
* @psalm-return numeric-string
*
* @psalm-pure
*/
public static function multiply(string $amount, string $multiplier): string;
/**
* Divide amount with divisor.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $divisor
*
* @psalm-return numeric-string
*
* @throws InvalidArgumentException when $divisor is zero.
*
* @psalm-pure
*/
public static function divide(string $amount, string $divisor): string;
/**
* Round number to following integer.
*
* @psalm-param numeric-string $number
*
* @psalm-return numeric-string
*
* @psalm-pure
*/
public static function ceil(string $number): string;
/**
* Round number to preceding integer.
*
* @psalm-param numeric-string $number
*
* @psalm-return numeric-string
*
* @psalm-pure
*/
public static function floor(string $number): string;
/**
* Returns the absolute value of the number.
*
* @psalm-param numeric-string $number
*
* @psalm-return numeric-string
*
* @psalm-pure
*/
public static function absolute(string $number): string;
/**
* Round number, use rounding mode for tie-breaker.
*
* @psalm-param numeric-string $number
* @psalm-param Money::ROUND_* $roundingMode
*
* @psalm-return numeric-string
*
* @psalm-pure
*/
public static function round(string $number, int $roundingMode): string;
/**
* Share amount among ratio / total portions.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $ratio
* @psalm-param numeric-string $total
*
* @psalm-return numeric-string
*
* @psalm-pure
*/
public static function share(string $amount, string $ratio, string $total): string;
/**
* Get the modulus of an amount.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $divisor
*
* @psalm-return numeric-string
*
* @throws InvalidArgumentException when $divisor is zero.
*
* @psalm-pure
*/
public static function mod(string $amount, string $divisor): string;
}