1 | <?php |
||
5 | class Fraction |
||
6 | { |
||
7 | /** @var int $whole */ |
||
8 | private $whole; |
||
9 | |||
10 | /** @var int $numerator */ |
||
11 | private $numerator; |
||
12 | |||
13 | /** @var int $denominator */ |
||
14 | private $denominator; |
||
15 | |||
16 | /** @var bool $negative */ |
||
17 | private $negative; |
||
18 | |||
19 | 4 | public function __construct($whole = 0, $numerator = 0, $denominator = 1) |
|
26 | |||
27 | /** |
||
28 | * @return int |
||
29 | */ |
||
30 | 1 | public function getWhole() |
|
34 | |||
35 | /** |
||
36 | * @param int $whole |
||
37 | * @return Fraction |
||
38 | */ |
||
39 | 4 | public function setWhole($whole) |
|
44 | |||
45 | /** |
||
46 | * @return int |
||
47 | */ |
||
48 | 1 | public function getNumerator() |
|
52 | |||
53 | /** |
||
54 | * @param int $numerator |
||
55 | * @return Fraction |
||
56 | */ |
||
57 | 4 | public function setNumerator($numerator) |
|
62 | |||
63 | /** |
||
64 | * @return int |
||
65 | */ |
||
66 | 1 | public function getDenominator() |
|
70 | |||
71 | /** |
||
72 | * @param int $denominator |
||
73 | * @return Fraction |
||
74 | */ |
||
75 | 4 | public function setDenominator($denominator) |
|
80 | |||
81 | 1 | private function refactor() |
|
91 | |||
92 | 1 | private function refactorWhole() |
|
100 | |||
101 | 1 | private function refactorFraction() |
|
107 | |||
108 | /** |
||
109 | * @param int $x |
||
110 | * @param int $y |
||
111 | * @return int |
||
112 | */ |
||
113 | 1 | private function getGreatestCommonDenominator($x, $y) |
|
127 | |||
128 | /** |
||
129 | * @param int $num |
||
130 | * @return array The common denominators of $num |
||
131 | */ |
||
132 | 1 | private function getFactors($num) |
|
143 | |||
144 | /** |
||
145 | * @return bool |
||
146 | */ |
||
147 | public function isNegative() |
||
151 | |||
152 | /** |
||
153 | * @param bool $negative |
||
154 | * @return Fraction |
||
155 | */ |
||
156 | public function setNegative($negative) |
||
161 | |||
162 | /** |
||
163 | * @return bool |
||
164 | */ |
||
165 | 1 | public function isInteger() |
|
169 | |||
170 | /** |
||
171 | * @return string |
||
172 | */ |
||
173 | 1 | public function __toString() |
|
184 | |||
185 | /** |
||
186 | * @return float |
||
187 | */ |
||
188 | 1 | public function toDecimal() |
|
197 | } |