|
9 | 9 | * @see http://sine.codeplex.com/SourceControl/changeset/view/57274#1535069 |
10 | 10 | * @ext bcmath |
11 | 11 | */ |
12 | | -abstract class BigNum extends \lang\Object { |
| 12 | +abstract class BigNum implements \lang\Value { |
13 | 13 | protected $num; |
14 | 14 |
|
15 | 15 | static function __static() { |
@@ -53,41 +53,44 @@ public function multiply($other) { |
53 | 53 | * @return math.BigNum |
54 | 54 | */ |
55 | 55 | public abstract function divide($other); |
56 | | - |
57 | | - /** |
58 | | - * Returns whether another object is equal to this |
59 | | - * |
60 | | - * @param lang.Generic cmp |
61 | | - * @return bool |
62 | | - */ |
63 | | - public function equals($cmp) { |
64 | | - return $cmp instanceof $this && 0 === bccomp($cmp->num, $this->num); |
65 | | - } |
66 | 56 |
|
67 | 57 | /** |
68 | 58 | * Returns an integer representing this bignum |
69 | 59 | * |
70 | | - * @return int |
| 60 | + * @return int |
71 | 61 | */ |
72 | | - public function intValue() { |
73 | | - return (int)substr($this->num, 0, strcspn($this->num, '.')); |
74 | | - } |
| 62 | + public function intValue() { return (int)substr($this->num, 0, strcspn($this->num, '.')); } |
75 | 63 |
|
76 | 64 | /** |
77 | 65 | * Returns a double representing this bignum |
78 | 66 | * |
79 | | - * @return int |
| 67 | + * @return double |
80 | 68 | */ |
81 | | - public function doubleValue() { |
82 | | - return (double)$this->num; |
| 69 | + public function doubleValue() { return (double)$this->num; } |
| 70 | + |
| 71 | + /** @return string */ |
| 72 | + public function toString() { return nameof($this).'('.$this->num.')'; } |
| 73 | + |
| 74 | + /** @return string */ |
| 75 | + public function hashCode() { return $this->num; } |
| 76 | + |
| 77 | + /** |
| 78 | + * Compare another value to this bignum |
| 79 | + * |
| 80 | + * @param var $value |
| 81 | + * @return int |
| 82 | + */ |
| 83 | + public function compareTo($value) { |
| 84 | + return $value instanceof $this ? bccomp($this->num, $value->num) : 1; |
83 | 85 | } |
84 | 86 |
|
85 | 87 | /** |
86 | | - * Returns a string representation |
| 88 | + * Returns whether another object is equal to this |
87 | 89 | * |
88 | | - * @return string |
| 90 | + * @param var $value |
| 91 | + * @return bool |
89 | 92 | */ |
90 | | - public function toString() { |
91 | | - return typeof($this).'('.(string)$this.')'; |
| 93 | + public function equals($value) { |
| 94 | + return $value instanceof $this && 0 === bccomp($this->num, $value->num); |
92 | 95 | } |
93 | 96 | } |
0 commit comments