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

Method mul

projects/JavaScript/proto/int64.js:615–686  ·  view source on GitHub ↗

* Multiply this value with other one * @this {!Int64} * @param {!Int64|!UInt64|number|string} other Other value * @returns {!Int64} Multiplication of two values

(other)

Source from the content-addressed store, hash-verified

613 * @returns {!Int64} Multiplication of two values
614 */
615 mul (other) {
616 if (this.isZero) {
617 return INT64_ZERO
618 }
619 if (!Int64.isInt64(other) && !UInt64.isUInt64(other)) {
620 other = Int64.fromValue(other)
621 }
622
623 if (other.isZero) {
624 return INT64_ZERO
625 }
626 if (this.eq(INT64_MIN)) {
627 return other.isOdd ? INT64_MIN : INT64_ZERO
628 }
629 if (other.eq(INT64_MIN)) {
630 return this.isOdd ? INT64_MIN : INT64_ZERO
631 }
632
633 if (this.isNegative) {
634 if (other.isNegative) {
635 return this.neg().mul(other.neg())
636 } else {
637 return this.neg().mul(other).neg()
638 }
639 } else if (other.isNegative) {
640 return this.mul(other.neg()).neg()
641 }
642
643 // If both longs are small, use float multiplication
644 if (this.lt(INT64_TWO_PWR_24) && other.lt(INT64_TWO_PWR_24)) {
645 return Int64.fromNumber(this.toNumber() * other.toNumber())
646 }
647
648 // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
649 // We can skip products that would overflow.
650
651 let a48 = this.high >>> 16
652 let a32 = this.high & 0xFFFF
653 let a16 = this.low >>> 16
654 let a00 = this.low & 0xFFFF
655
656 let b48 = other.high >>> 16
657 let b32 = other.high & 0xFFFF
658 let b16 = other.low >>> 16
659 let b00 = other.low & 0xFFFF
660
661 let c48 = 0
662 let c32 = 0
663 let c16 = 0
664 let c00 = 0
665 c00 += a00 * b00
666 c16 += c00 >>> 16
667 c00 &= 0xFFFF
668 c16 += a16 * b00
669 c32 += c16 >>> 16
670 c16 &= 0xFFFF
671 c16 += a00 * b16
672 c32 += c16 >>> 16

Callers 15

fromStringMethod · 0.45
toStringMethod · 0.45
divMethod · 0.45
modMethod · 0.45
fromStringMethod · 0.45
toStringMethod · 0.45
mulMethod · 0.45
divMethod · 0.45
modMethod · 0.45
getMethod · 0.45
setMethod · 0.45
setMethod · 0.45

Calls 9

eqMethod · 0.95
negMethod · 0.95
ltMethod · 0.95
toNumberMethod · 0.95
isInt64Method · 0.80
isUInt64Method · 0.80
fromValueMethod · 0.45
fromNumberMethod · 0.45
fromBitsMethod · 0.45

Tested by

no test coverage detected