Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
matanl263310yDoesn't even save time on computation, cache abuse since it destroys locality and what else... Horrible code -
@filthyranter because they are dumb. They thought that if you give a long long, you should get a long long, even though it maxes out in value at fucking 18.
-
QoolQuy200051910yHa! What prat wrote that code? Obviously he should have used a for loop instead...
-
elazar101610yThere may be good reasons for writing such code, although I believe there are none in this case, as proven by the return type and the redundant >= tests -
bkwilliams718410yLooking at is again, thanks to notifs; it's also wrong for negative numbers there is no default return. -
alcatraz627885510yI'm thinking about how even if someone intentionally wanted to write that, they'd run a loop to print the code. -
jamesh33010yI like how there's a staircase of small travesties leading up to the big one. It helps the reader mentally prepare. -
OrestH74610yI predict, that you haven't ever heared about logarithms =) a guy above posted a good inline form of counting nunber of digits in the number ( floor(log10(x)) + 1) ) -
jamesh33010y@OrestH my guess actually is the code in the image is more efficient (discounting the long long and unnecessary comparisons) because there would be one instruction for each case.
A log is probably a few instructions, one more for add, one comparison...
I'll confess I probably would have used sprintf and strlen because I'm lazy and that's the worst option.. -
elazar101610y@alebianco the cpu will likely execute the instructions out of order - i.e. in parallel in the same core, since there are no real interdependencies there. So it may very well be faster than any floating-point operation (or a conversion to string, or an unrolled loop) -
perfectdark263510yI think convert to string and count length is slightly faster than log? I guess it depends on the language -
ohemelaar357010yWhat really bugs me is that on line 10 the semicolon is suddenly displaced by 3 to the right instead of 2 on the other lines

You, I heard you have some memory to waste
undefined