* Returns true if this value equals other. * NaN === NaN → false (standard NaN semantics).
(other: BigDecimal | number)
| 344 | * NaN === NaN → false (standard NaN semantics). |
| 345 | */ |
| 346 | eq(other: BigDecimal | number): boolean { |
| 347 | if (typeof other === 'number') { |
| 348 | // The 0/1/-1 fast paths use exponent===0 which excludes NaN (exp=NaN). |
| 349 | if (other === 0) return this.significand === 0n && this.exponent === 0; |
| 350 | if (other === 1) return this.significand === 1n && this.exponent === 0; |
| 351 | if (other === -1) return this.significand === -1n && this.exponent === 0; |
| 352 | // Integer fast path: compare directly when possible |
| 353 | if ( |
| 354 | Number.isInteger(other) && |
| 355 | Number.isFinite(this.exponent) && |
| 356 | this.exponent >= 0 && |
| 357 | this.exponent <= 15 |
| 358 | ) { |
| 359 | return this.significand * pow10(this.exponent) === BigInt(other); |
| 360 | } |
| 361 | // cmp returns NaN for NaN inputs, so NaN === 0 → false (correct) |
| 362 | return this.cmp(other) === 0; |
| 363 | } |
| 364 | // Both normalized → equal values have identical (significand, exponent) |
| 365 | // NaN: exponent is NaN, and NaN !== NaN, so the === check returns false |
| 366 | return ( |
| 367 | this.significand === other.significand && this.exponent === other.exponent |
| 368 | ); |
| 369 | } |
| 370 | |
| 371 | /** Returns true if this value is strictly less than other. */ |
| 372 | lt(other: BigDecimal | number): boolean { |