* Add this value to other one * @this {!Int64} * @param {!Int64|!UInt64|number|string} other Other value * @returns {!Int64} Sum of the values
(other)
| 559 | * @returns {!Int64} Sum of the values |
| 560 | */ |
| 561 | add (other) { |
| 562 | if (!Int64.isInt64(other) && !UInt64.isUInt64(other)) { |
| 563 | other = Int64.fromValue(other) |
| 564 | } |
| 565 | |
| 566 | // Divide each number into 4 chunks of 16 bits, and then sum the chunks |
| 567 | |
| 568 | let a48 = this.high >>> 16 |
| 569 | let a32 = this.high & 0xFFFF |
| 570 | let a16 = this.low >>> 16 |
| 571 | let a00 = this.low & 0xFFFF |
| 572 | |
| 573 | let b48 = other.high >>> 16 |
| 574 | let b32 = other.high & 0xFFFF |
| 575 | let b16 = other.low >>> 16 |
| 576 | let b00 = other.low & 0xFFFF |
| 577 | |
| 578 | let c48 = 0 |
| 579 | let c32 = 0 |
| 580 | let c16 = 0 |
| 581 | let c00 = 0 |
| 582 | c00 += a00 + b00 |
| 583 | c16 += c00 >>> 16 |
| 584 | c00 &= 0xFFFF |
| 585 | c16 += a16 + b16 |
| 586 | c32 += c16 >>> 16 |
| 587 | c16 &= 0xFFFF |
| 588 | c32 += a32 + b32 |
| 589 | c48 += c32 >>> 16 |
| 590 | c32 &= 0xFFFF |
| 591 | c48 += a48 + b48 |
| 592 | c48 &= 0xFFFF |
| 593 | return Int64.fromBits((c16 << 16) | c00, (c48 << 16) | c32) |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * Subtract other value from this value |