Line | |
---|
1 | /*
|
---|
2 | * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
---|
3 | * See the copyright notice in the ACK home directory, in the file "Copyright".
|
---|
4 | */
|
---|
5 | /* $Header: /cvsup/minix/src/lib/ansi/div.c,v 1.1.1.1 2005/04/21 14:56:04 beng Exp $ */
|
---|
6 |
|
---|
7 | #include <stdlib.h>
|
---|
8 |
|
---|
9 | static int tmp = -1;
|
---|
10 |
|
---|
11 | div_t
|
---|
12 | div(register int numer, register int denom)
|
---|
13 | {
|
---|
14 | div_t r;
|
---|
15 |
|
---|
16 | /* The assignment of tmp should not be optimized !! */
|
---|
17 | if (tmp == -1) {
|
---|
18 | tmp = (tmp / 2 == 0);
|
---|
19 | }
|
---|
20 | if (numer == 0) {
|
---|
21 | r.quot = numer / denom; /* might trap if denom == 0 */
|
---|
22 | r.rem = numer % denom;
|
---|
23 | } else if ( !tmp && ((numer < 0) != (denom < 0))) {
|
---|
24 | r.quot = (numer / denom) + 1;
|
---|
25 | r.rem = numer - (numer / denom + 1) * denom;
|
---|
26 | } else {
|
---|
27 | r.quot = numer / denom;
|
---|
28 | r.rem = numer % denom;
|
---|
29 | }
|
---|
30 | return r;
|
---|
31 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.