Xianqiao Wang

Xianqiao Wang

Some records of life and study

  • Home

计算两个整数之和

https://techiedelight.quora.com/Top-25-Programming-Puzzles-and-Brain-Teasers

半加法逻辑:
function add(a, b) {
if (!b) return a;
const sum = a ^ b; // 异或。对等位相加,没有进位
const carry = (a & b) << 1; // 进位
return add(sum, carry)
}

使用对数:Math.log(Math.exp(10) * Math.exp(20))


Published by Xianqiao Wang on November 21st, 2018

  • Algorithm
  • Math
  • RSS

© 2025 Xianqiao's Site.

Design by Fabien Penso. Powered by Postach.io