(y: BigDecimal | number | string | bigint)
| 275 | } |
| 276 | |
| 277 | plus(y: BigDecimal | number | string | bigint): BigDecimal { |
| 278 | const other = BigDecimal._coerce(y) |
| 279 | if (this._special || other._special) { |
| 280 | return this._specialArith(other, 'plus') |
| 281 | } |
| 282 | if (this._mantissa === 0n && other._mantissa === 0n) { |
| 283 | // -0 + -0 = -0, otherwise 0 |
| 284 | const negZero = this._negativeZero && other._negativeZero |
| 285 | return BigDecimal._create(0n, 0, SpecialValue.NONE, negZero) |
| 286 | } |
| 287 | if (this._mantissa === 0n) return other |
| 288 | if (other._mantissa === 0n) return this |
| 289 | |
| 290 | // Align exponents |
| 291 | let m1 = this._mantissa |
| 292 | let m2 = other._mantissa |
| 293 | const e1 = this._exponent |
| 294 | const e2 = other._exponent |
| 295 | const minE = Math.min(e1, e2) |
| 296 | if (e1 > minE) m1 *= bigintPow10(e1 - minE) |
| 297 | if (e2 > minE) m2 *= bigintPow10(e2 - minE) |
| 298 | |
| 299 | const sum = m1 + m2 |
| 300 | if (sum === 0n) { |
| 301 | return BigDecimal._create(0n, 0, SpecialValue.NONE, false) |
| 302 | } |
| 303 | const [nm, ne] = removeTrailingZeros(sum, minE) |
| 304 | return BigDecimal._create(nm, ne, SpecialValue.NONE, false) |
| 305 | } |
| 306 | |
| 307 | minus(y: BigDecimal | number | string | bigint): BigDecimal { |
| 308 | return this.plus(BigDecimal._coerce(y).negated()) |
no test coverage detected