MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / add

Method add

projects/JavaScript/proto/int64.js:1472–1505  ·  view source on GitHub ↗

* Add this value to other one * @this {!UInt64} * @param {!Int64|!UInt64|number|string} other Other value * @returns {!UInt64} Sum of two values

(other)

Source from the content-addressed store, hash-verified

1470 * @returns {!UInt64} Sum of two values
1471 */
1472 add (other) {
1473 if (!Int64.isInt64(other) && !UInt64.isUInt64(other)) {
1474 other = UInt64.fromValue(other)
1475 }
1476
1477 // Divide each number into 4 chunks of 16 bits, and then sum the chunks
1478
1479 let a48 = this.high >>> 16
1480 let a32 = this.high & 0xFFFF
1481 let a16 = this.low >>> 16
1482 let a00 = this.low & 0xFFFF
1483
1484 let b48 = other.high >>> 16
1485 let b32 = other.high & 0xFFFF
1486 let b16 = other.low >>> 16
1487 let b00 = other.low & 0xFFFF
1488
1489 let c48 = 0
1490 let c32 = 0
1491 let c16 = 0
1492 let c00 = 0
1493 c00 += a00 + b00
1494 c16 += c00 >>> 16
1495 c00 &= 0xFFFF
1496 c16 += a16 + b16
1497 c32 += c16 >>> 16
1498 c16 &= 0xFFFF
1499 c32 += a32 + b32
1500 c48 += c32 >>> 16
1501 c32 &= 0xFFFF
1502 c48 += a48 + b48
1503 c48 &= 0xFFFF
1504 return UInt64.fromBits((c16 << 16) | c00, (c48 << 16) | c32)
1505 }
1506
1507 /**
1508 * Subtract other value from this value

Callers 1

subMethod · 0.95

Calls 4

isInt64Method · 0.80
isUInt64Method · 0.80
fromValueMethod · 0.45
fromBitsMethod · 0.45

Tested by

no test coverage detected