high bits of long multiplication in Java?

前端 未结 7 997
说谎
说谎 2020-12-19 14:35

Is there any way to get the high half of the multiplication of two longs in Java? I.e. the part that vanishes due to overflow. (So the upper 64 bits of the 128-

7条回答
  •  清歌不尽
    2020-12-19 15:10

    Java 9 has Math.multiplyHigh, which according to the Javadocs "Returns as a long the most significant 64 bits of the 128-bit product of two 64-bit factors."

提交回复
热议问题