Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / system / libroot / posix / stdlib / div.c
blob0ca8e3326fbb5c90316f61d76ebe6a3a2ce2c87c
1 /*
2 * Copyright 2002-2010, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Author:
6 * Daniel Reinhold, danielre@users.sf.net
7 * Tri-Edge AI, triedgeai@gmail.com
8 */
11 #include <stdlib.h>
14 div_t
15 div(int numerator, int denominator)
17 div_t val;
19 val.quot = numerator / denominator;
20 val.rem = numerator % denominator;
22 if (numerator >= 0 && val.rem < 0) {
23 val.rem -= denominator;
24 ++val.quot;
27 return val;
31 ldiv_t
32 ldiv(long numerator, long denominator)
34 ldiv_t val;
36 val.quot = numerator / denominator;
37 val.rem = numerator % denominator;
39 if (numerator >= 0 && val.rem < 0) {
40 val.rem -= denominator;
41 ++val.quot;
44 return val;
48 lldiv_t
49 lldiv(long long numerator, long long denominator)
51 lldiv_t val;
53 val.quot = numerator / denominator;
54 val.rem = numerator % denominator;
56 if (numerator >= 0 && val.rem < 0) {
57 val.rem -= denominator;
58 ++val.quot;
61 return val;