![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
Problem converting double to int
First of all, this is standard C.
I have a statement in my code like this: int x = log(8)/log(2) After much confusion I found that x was assigned 2. This is not what I want though. I know that log(8)/log(2) equals 3.000000... in double and I want it to convert that to the integer 3 and save it into x. For some reason it will not do this though. I have tested by just putting double x = 3;
int a = x;
printf("a: %d", a);I also tried this: double x = log(8)/log(2);
int a = ceil(x);
printf("a: %d", a);The actual use of the statement in my code is in a function: arrayInsert(int n, int *array){
int a = log(n)/log(2);
int b = a - 1;
int j = n + pow(2, b);
.
.
.
} |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|