mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 06:32:44 +00:00 
			
		
		
		
	LibC: Make div() and ldiv() behave according to the C standard
This commit is contained in:
		
							parent
							
								
									b009f8522c
								
							
						
					
					
						commit
						0b59c0d0dc
					
				
					 1 changed files with 10 additions and 0 deletions
				
			
		|  | @ -348,6 +348,11 @@ div_t div(int numerator, int denominator) | |||
|     div_t result; | ||||
|     result.quot = numerator / denominator; | ||||
|     result.rem = numerator % denominator; | ||||
| 
 | ||||
|     if (numerator >= 0 && result.rem < 0) { | ||||
|         result.quot++; | ||||
|         result.rem -= denominator; | ||||
|     } | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
|  | @ -356,6 +361,11 @@ ldiv_t ldiv(long numerator, long denominator) | |||
|     ldiv_t result; | ||||
|     result.quot = numerator / denominator; | ||||
|     result.rem = numerator % denominator; | ||||
| 
 | ||||
|     if (numerator >= 0 && result.rem < 0) { | ||||
|         result.quot++; | ||||
|         result.rem -= denominator; | ||||
|     } | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling