Skip to content

Commit 1f1fbe2

Browse files
committed
Implement lang.Value instead of extending lang.Object
1 parent 0b5677f commit 1f1fbe2

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

src/main/php/math/BigNum.class.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @see http://sine.codeplex.com/SourceControl/changeset/view/57274#1535069
1010
* @ext bcmath
1111
*/
12-
abstract class BigNum extends \lang\Object {
12+
abstract class BigNum implements \lang\Value {
1313
protected $num;
1414

1515
static function __static() {
@@ -53,41 +53,44 @@ public function multiply($other) {
5353
* @return math.BigNum
5454
*/
5555
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-
}
6656

6757
/**
6858
* Returns an integer representing this bignum
6959
*
70-
* @return int
60+
* @return int
7161
*/
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, '.')); }
7563

7664
/**
7765
* Returns a double representing this bignum
7866
*
79-
* @return int
67+
* @return double
8068
*/
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;
8385
}
8486

8587
/**
86-
* Returns a string representation
88+
* Returns whether another object is equal to this
8789
*
88-
* @return string
90+
* @param var $value
91+
* @return bool
8992
*/
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);
9295
}
9396
}

0 commit comments

Comments
 (0)