1 /* 2 * Copyright 2002-2007, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Author: 6 * Daniel Reinhold, danielre@users.sf.net 7 */ 8 9 10 #include <stdlib.h> 11 12 13 div_t 14 div(int numerator, int denominator) 15 { 16 div_t val; 17 18 val.quot = numerator / denominator; 19 val.rem = numerator - denominator * val.quot; 20 21 if (val.rem > 0 && val.quot < 0) { 22 val.rem -= denominator; 23 ++val.quot; 24 } 25 26 return val; 27 } 28 29 30 ldiv_t 31 ldiv(long numerator, long denominator) 32 { 33 ldiv_t val; 34 35 val.quot = numerator / denominator; 36 val.rem = numerator - denominator * val.quot; 37 38 if (val.rem > 0 && val.quot < 0) { 39 val.rem -= denominator; 40 ++val.quot; 41 } 42 43 return val; 44 } 45