| View previous topic :: View next topic |
| Author |
Message |
steffven
Joined: 19 May 2008 Posts: 28
|
Posted: Thu May 29, 2008 6:24 am Post subject: PSP makes faults while rounding?!? |
|
|
| Code: | temp2 = ceil((temp / 34));
printf("%d | %d", temp2, temp); |
It prints out "0 | 13", "1 | 13" would be right.
Another time it prints out "1 | 45", "2 | 45" would be right.
Does somebody know where my fault is? |
|
| Back to top |
|
 |
cyberfish
Joined: 19 May 2008 Posts: 19
|
Posted: Thu May 29, 2008 6:35 am Post subject: |
|
|
C/C++ integer division doesn't round. It truncates.
So it becomes essentially
| Code: |
temp2 = ceil((0));
printf("%d | %d", temp2, temp);
|
Assuming temp is an integer. |
|
| Back to top |
|
 |
bullcrap0
Joined: 17 Apr 2008 Posts: 3
|
Posted: Thu May 29, 2008 9:46 am Post subject: |
|
|
check this out http://codepad.org/R5CZ4sc0
EDIT: I hope you notice the 34. <- that's 34DOT
Or you could just type 34.0 |
|
| Back to top |
|
 |
jbit Site Admin

Joined: 28 May 2005 Posts: 293 Location: København, Danmark
|
Posted: Thu May 29, 2008 5:34 pm Post subject: |
|
|
| Please keep this forum PSP related |
|
| Back to top |
|
 |
|