22

It works.. I guess? 🤣🤣

Comments
  • 0
    why is it type long long tho?
  • 3
    Half the conditions are redundant, but what would you expect from that code...
  • 1
    Everything is four anyway
  • 4
    Why don't you just convert it to a string and return the number of chars? 🤔
  • 0
  • 4
    @They because that is ~80 times more expensive. Log10 is an infinitely better choice.
  • 0
    @calmyourtities because what other type can fit that much information?!
  • 14
    Benchmark this versus all other approaches. You'll find this (or rather: an optimized version of this killing half the compares) is the most performant.

    When every cycle matters, all the fancy approaches (especially anything using friggin' string casting) are worse than useless.

    Come on. It's like people don't understand memory and clocks even exist. 😡
  • 3
    @Root I almost thought that noone would understand it in the age of VM languages or JavaScript / python all over the place... Luv ya'
  • 0
    It’s called art.
  • 2
    @Root in that case I would expect a comment explaining exactly that. Even if it is faster, you need to stop people from being "smart" trying to refactor it.

    Such hacks should be documented if they're needed.
  • 0
    @Root it is only going to return a number less than 255, why not make it a short
  • 1
    @calmyourtities ahh I assumed you meant the arg type; apologies! Yeah. No idea. It should absolutely be a byte/unsigned char/short, though.
  • 0
    @calmyourtities @Root not at all. You should use the types defines in stdint.h. Everything else is dangerous and should be avoided.
Add Comment