(
other: BigDecimal,
op: 'times' | 'div' | 'plus'
)
| 697 | } |
| 698 | |
| 699 | private _specialArith( |
| 700 | other: BigDecimal, |
| 701 | op: 'times' | 'div' | 'plus' |
| 702 | ): BigDecimal { |
| 703 | const a = this._special |
| 704 | const b = other._special |
| 705 | |
| 706 | // NaN propagates |
| 707 | if (a === SpecialValue.NAN || b === SpecialValue.NAN) { |
| 708 | return BigDecimal._create(0n, 0, SpecialValue.NAN, false) |
| 709 | } |
| 710 | |
| 711 | const aNeg = this._isSignNegative() |
| 712 | const bNeg = other._isSignNegative() |
| 713 | const aInf = |
| 714 | a === SpecialValue.POSITIVE_INFINITY || |
| 715 | a === SpecialValue.NEGATIVE_INFINITY |
| 716 | const bInf = |
| 717 | b === SpecialValue.POSITIVE_INFINITY || |
| 718 | b === SpecialValue.NEGATIVE_INFINITY |
| 719 | |
| 720 | if (op === 'times') { |
| 721 | if (aInf || bInf) { |
| 722 | if ( |
| 723 | (aInf && other._mantissa === 0n && !bInf) || |
| 724 | (bInf && this._mantissa === 0n && !aInf) |
| 725 | ) { |
| 726 | return BigDecimal._create(0n, 0, SpecialValue.NAN, false) |
| 727 | } |
| 728 | const neg = aNeg !== bNeg |
| 729 | return BigDecimal._create( |
| 730 | 0n, |
| 731 | 0, |
| 732 | neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, |
| 733 | false |
| 734 | ) |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | if (op === 'div') { |
| 739 | if (aInf && bInf) { |
| 740 | return BigDecimal._create(0n, 0, SpecialValue.NAN, false) |
| 741 | } |
| 742 | if (aInf) { |
| 743 | const neg = aNeg !== bNeg |
| 744 | return BigDecimal._create( |
| 745 | 0n, |
| 746 | 0, |
| 747 | neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY, |
| 748 | false |
| 749 | ) |
| 750 | } |
| 751 | if (bInf) { |
| 752 | const negZero = aNeg !== bNeg |
| 753 | return BigDecimal._create(0n, 0, SpecialValue.NONE, negZero) |
| 754 | } |
| 755 | } |
| 756 |
no test coverage detected