blob: 3a00d9143e0f58eb8fafb24a88e9866a062e6c42 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*
* |-----------------------------------------------------------|
* | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc. |
* | All Rights Reserved |
* |-----------------------------------------------------------|
* | Restricted Rights Legend |
* | Use, duplication, or disclosure by the Government is |
* | subject to restrictions as set forth in |
* | subparagraph (c)(1)(ii) of the Rights in Technical |
* | Data and Computer Software Clause of DFARS 252.227-7013. |
* | MIPS Computer Systems, Inc. |
* | 950 DeGuigne Avenue |
* | Sunnyvale, California 94088-3650, USA |
* |-----------------------------------------------------------|
*/
#ident "$Header: llabsdiv.c,v 3010.1 92/05/15 17:22:16 murphy Exp $"
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/* This is loosely based on: */
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
/* The copyright notice above does not evidence any */
/* actual or intended publication of such source code. */
/*LINTLIBRARY*/
#include <stdlib.h>
#include "lldefs.h"
typedef struct {
long_long quot;
long_long rem;
} lldiv_t;
/* ANSI 4.10.6.1 */
long_long
llabs(arg)
long_long arg;
{
return (arg >= 0 ? arg : -arg);
}
/* ANSI 4.10.6.2 */
lldiv_t lldiv(numer, denom)
long_long numer;
long_long denom;
{
lldiv_t sd;
if (numer >= 0 && denom < 0) {
numer = -numer;
sd.quot = -(numer / denom);
sd.rem = -(numer % denom);
} else if (numer < 0 && denom > 0) {
denom = -denom;
sd.quot = -(numer / denom);
sd.rem = numer % denom;
} else {
sd.quot = numer / denom;
sd.rem = numer % denom;
}
return(sd);
}
|