Talk:Even or odd: Difference between revisions

added definition of odd/even numbers. ~~~~
(→‎Silly recursive solution: Trickier to optimize than you seem to think…)
(added definition of odd/even numbers. ~~~~)
Line 7:
}</lang> --[[User:Mwn3d|Mwn3d]] 18:47, 1 December 2011 (UTC)
: I'd be quite surprised if anything optimized that very much, as it depends on applying an operation to the result of each recursive call which is usually a sign that the compiler ''won't'' be able to figure things out. A human could split that into a pair of functions that are the logical inverse of each other (i.e., isEven and notIsEven) which could then admit optimization, but I suspect that sort of analysis isn't done by compilers (on the grounds that it would so rarely lead to real optimizations in practice). –[[User:Dkf|Donal Fellows]] 09:48, 2 December 2011 (UTC)
 
== definition of even & odd numbers ==
This may be frivolous/trivial, but since the task is to determine if a number is odd or even, a simple definition of an odd/even number could be in order.
<br><br>From MathWorld:
<br><br>An odd number is an integer of the form n=2k+1 where k is an integer.
<br><br>Integers which are not odd are called even.
<br><br>The above definition has the advantage that it isn't dependent upon its (say, internal binary) representation (or any base, for that matter), although that is one method to determine evenness/oddness. [[User:Gerard Schildberger|Gerard Schildberger]] 00:46, 16 March 2012 (UTC)