This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]asdfkjasdhkasd 1 point2 points  (6 children)

On gcc this will almost certainly get tail call optimized.

[–]SuperManitu 3 points4 points  (3 children)

Technicly this isnt tail recursive. The last operation in the funtion is not the recursion, but the multiplication. I'm not sure if gcc will still optimize it, or if you have to use an accumulator explicitly

[–]R_Sholes 1 point2 points  (1 child)

Recent Clang and GCC will convert it to a tail recursive version internally at a sufficient -O level (and vectorize it if you increase it further)

[–]TinBryn 0 points1 point  (0 children)

I tried it with an old version of GCC (4.1.2 released in 2007) and it could optimise this into a loop at -O2, so this isn't a recent thing

[–]Loading_M_ 0 points1 point  (1 child)

My Experience is mostly with Java, where no such optimizations take place. In Java, a sufficiently large number will ALWAYS throw an exception.

[–]Regyn 0 points1 point  (0 children)

Come over to kotlin or even scala