Skip to content

Instantly share code, notes, and snippets.

@jougene
Created June 7, 2016 11:42
Show Gist options
  • Save jougene/58173d8e584cfb6b7e9680e90ba72cab to your computer and use it in GitHub Desktop.
Save jougene/58173d8e584cfb6b7e9680e90ba72cab to your computer and use it in GitHub Desktop.
function mulByAdd(a, b) {
	var iter = function (res, a, b) {
		if (b == 0) {
			return res;
		}
		if (b % 2 == 0) {
			return iter(res, a << 1, b >> 1)
		}
		return iter(res + a, a, b - 1)
	}
	return iter(0, a, b);
}
@deadem
Copy link

deadem commented Jun 7, 2016

b & 1 == 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment