Adds the two's-complement representation of Decimal128 b to result in place. The 128-bit operand is sign-extended to 256 bits before performing the addition. This helper assumes that both operands already share the same scale and that the resulting value fits within a {@l
(Decimal256 result, Decimal128 b)
| 854 | * @param b the 128-bit value to add, interpreted using two's-complement semantics |
| 855 | */ |
| 856 | public static void uncheckedAdd(Decimal256 result, Decimal128 b) { |
| 857 | long sign = b.getHigh() < 0 ? -1L : 0L; |
| 858 | long r = result.ll + b.getLow(); |
| 859 | long carry = hasCarry(result.ll, r) ? 1L : 0L; |
| 860 | result.ll = r; |
| 861 | |
| 862 | long t = result.lh + carry; |
| 863 | carry = hasCarry(result.lh, t) ? 1L : 0L; |
| 864 | r = t + b.getHigh(); |
| 865 | carry |= hasCarry(t, r) ? 1L : 0L; |
| 866 | result.lh = r; |
| 867 | |
| 868 | t = result.hl + carry; |
| 869 | carry = hasCarry(result.hl, t) ? 1L : 0L; |
| 870 | r = t + sign; |
| 871 | carry |= hasCarry(t, r) ? 1L : 0L; |
| 872 | result.hl = r; |
| 873 | result.hh = result.hh + carry + sign; |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * Adds the two's-complement representation of {@link Decimal64} {@code b} to {@code result} in place. |