Created
October 17, 2010 20:41
-
-
Save schwern/631267 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int lengthi_log(int x) { | |
int length = 0; | |
if( x == 0 ) | |
return 1; | |
length = ceil(log10(abs(x))); | |
if( x < 0 ) | |
length++; | |
return length; | |
} | |
int lengthi_pow(int x) { | |
int length = 1; | |
int abs_x = abs(x); | |
while( pow(10, length) <= abs_x ) length++; | |
if( x < 0 ) | |
length++; | |
return length; | |
} | |
int main() { | |
int i; | |
for(i = 0; i < 10000000; i++ ){ | |
lengthi_pow(123); | |
lengthi_pow(1234); | |
lengthi_pow(-123); | |
lengthi_pow(0); | |
lengthi_pow(-0); | |
lengthi_pow(1234567); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment