Results 1 to 1 of 1
Code:
#include<cstdio>
#include<cmath>
int main(){
printf("%lf\n", log(8)/log(2) );
//case1:
double v=log(8)/log(2);
printf("%lld\n",(long long)v);
//case2:
printf("%lld\n",(long long)( log(8)/log(2) ));
//case3:
printf("%lld\n",(long long)(double)( log(8)/log(2) ));
//case4:
printf("%lld\n",(long long)(float)( log(8)/log(2) ));
}
output:
...
- 06-22-2010 #1Just Joined!
- Join Date
- Jan 2010
- Posts
- 4
Can any one please explain this output?
output:Code:#include<cstdio> #include<cmath> int main(){ printf("%lf\n", log(8)/log(2) ); //case1: double v=log(8)/log(2); printf("%lld\n",(long long)v); //case2: printf("%lld\n",(long long)( log(8)/log(2) )); //case3: printf("%lld\n",(long long)(double)( log(8)/log(2) )); //case4: printf("%lld\n",(long long)(float)( log(8)/log(2) )); }
Why is it not working properly while typecasting a double to long long,Code:3.000000 3 2 2 3
but it works fine when we downcast double to float and then float to long long?


Reply With Quote