# Implement multiplication without using any loops, branches or function calls [closed]

I came up with the following in GNU C

r=0;m(a,b){x:goto*(int*[]){&&x,&&y}[r+=a&1?0:b,a>>=1,b<<=1,a<1];y:;}


One could argue there is a branch here a&1?0:b

So I also came up with this one

r=0;m(a,b){x:goto*(int*[]){&&x,&&y}[r+=(int[]){0,b}[a&1],a>>=1,b<<=1,a<1];y:;}


I'm depending on implicit int here as well.

Can you make it any smaller?

Explanation of the above code, or at least parts of how I got there can be found here http://codepad.org/L0MvnCe9

Must not use function calls (recursion, standard library functions like fma, exp, etc), loops (while, for, do), or branches (if, ?:, etc). No using the divide or multiply operator either (that's cheating.) goto is allowed for branching.

Good luck!

## closed as unclear what you're asking by Ypnypn, Martin Ender, ProgramFOX, matsjoyce, NinjaBearMonkeyNov 10 '14 at 20:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• goto is a branch. – feersum Nov 10 '14 at 9:03
• It's just an obfuscated form of if(a<1)goto x;. If an exact list of operators, keywords etc. which can't be used is provided it could be a valid code golf problem though. – feersum Nov 10 '14 at 9:12
• @Tal It's simple but tedious to do it without any branch, as long as the size of int is known, by calculating each of the n bits from the n^2 interactions between bits. – feersum Nov 10 '14 at 10:39
• Is C the only allowed language? – ProgramFOX Nov 10 '14 at 10:46
• Could you rearrange the information a bit, as it took me a while to see what the rules are. Also, how does the code pad link give explanation? Since it's quite small, you could move it into the question as well. – matsjoyce Nov 10 '14 at 19:23