22

My own implementation for calculating if a number is even.
Full Code: https://ghostbin.com/paste/fkp6j

Comments
  • 0
    This kind of reminds me of my friend who wanted to add complexity to his code even though it was totally redundant to do so.
  • 3
    I assume this is a joke? I'm missing something. Is it supposed to be a comical example of overly verbose and complicated ways of achieving a trivial task. Also, and this may be deliberate, your array of evens is full of odds.
  • 5
    It's currently a meme. Especially in https://reddit.com/r/... there a many isEven functions which are more complicated as necessary
  • 0
    @Bimpfi OIC. That explains it. Thx.
  • 1
    Looks like some enterprise code to me :D
  • 1
    You are fooling us, right? 😅
  • 0
    @irene but you cant do log -1. but yeah it is wrong. he tests for !<= 0 and then adds 1. But this whole function is rubbish so...
  • 3
    bool isEven(n)
    {
    return n & 1 == 0;
    }
  • 1
    @rkzo that's the right way! I've the same function. 😉
  • 0
    simplest:

    if (int($x / 2) == ($x / 2)) {
    #Number is even
    }
  • 0
    Fuck divide and conquer.
    Multiply and surrender is the only way!
  • 0
    @rkzo that's wrong right? It only works with unsigned?
  • 0
    I dont see the point why this doesnt work for signed?
  • 0
    @scholl3ss a negative number will result in n_digits = 1.
  • 0
    Why? 2 complement? I dont get it.
  • 0
    @scholl3ss log function always returns something positive
  • 0
    Oh, i was talking about num & 1 == 0
  • 0
    @scholl3ss oh, then yes, 2 bits complement. With 4 bits, 1111 == -8
    And it fails.
Add Comment