1 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 2 #include <precomp.h> 3 4 /* 5 * @implemented 6 */ 7 div_t 8 CDECL 9 div(int num, int denom) 10 { 11 div_t r; 12 13 if (num > 0 && denom < 0) { 14 num = -num; 15 denom = -denom; 16 } 17 r.quot = num / denom; 18 r.rem = num % denom; 19 if (num < 0 && denom > 0) 20 { 21 if (r.rem > 0) 22 { 23 r.quot++; 24 r.rem -= denom; 25 } 26 } 27 return r; 28 } 29