Skip to content

Commit f7a8a1d

Browse files
committed
feat(Epoch): improve Epoch.compare
1 parent 3dfce54 commit f7a8a1d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/core/src/ckb/epoch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ export class Epoch extends mol.Entity.Base<EpochLike, Epoch>() {
165165
* representation: (number * length + index) scaled by the other's length.
166166
*
167167
* @param other - EpochLike value to compare against.
168-
* @returns positive if this > other, 0 if equal, negative if this < other.
168+
* @returns 1 if this > other, 0 if equal, -1 if this < other.
169169
*/
170-
compare(other: EpochLike): number {
170+
compare(other: EpochLike): 1 | 0 | -1 {
171171
if (this === other) {
172172
return 0;
173173
}
@@ -176,7 +176,7 @@ export class Epoch extends mol.Entity.Base<EpochLike, Epoch>() {
176176
const a = (this.number * this.length + this.index) * other_.length;
177177
const b = (other_.number * other_.length + other_.index) * this.length;
178178

179-
return Number(a - b);
179+
return a > b ? 1 : a < b ? -1 : 0;
180180
}
181181

182182
/**

0 commit comments

Comments
 (0)