Discuss the development of new homebrew software, tools and libraries.
	Moderators: cheriff, TyRaNiD
			
		
		
			- 
				
																			 steffven
- Posts: 28
- Joined: Mon May 19, 2008 7:37 pm
						
					
													
						
									
						Post
					
								by steffven » 
			
			
			
			
			Code: Select all
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?
 
		 
				
		
		 
	 
				
		
		
			- 
				
																			 cyberfish
- Posts: 19
- Joined: Mon May 19, 2008 3:39 pm
						
					
						
		
													
						
									
						Post
					
								by cyberfish » 
			
			
			
			
			C/C++ integer division doesn't round. It truncates.
So it becomes essentially 
Code: Select all
temp2 = ceil((0));
printf("%d | %d", temp2, temp);
Assuming temp is an integer.
 
		 
				
		
		 
	 
				
				
		
		
			- 
				
								jbit							
- Site Admin
- Posts: 293
- Joined: Sat May 28, 2005 3:11 am
- Location: København, Danmark
- 
				Contact:
				
			
						
					
						
		
													
						
									
						Post
					
								by jbit » 
			
			
			
			
			Please keep this forum PSP related