source: trunk/minix/lib/ansi/ldiv.c@ 12

Last change on this file since 12 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 778 bytes
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/ldiv.c,v 1.1.1.1 2005/04/21 14:56:05 beng Exp $ */
6
7#include <stdlib.h>
8
9static long tmp = -1;
10
11ldiv_t
12ldiv(register long numer, register long denom)
13{
14 ldiv_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.