forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdvi.c
More file actions
executable file
·68 lines (62 loc) · 1.06 KB
/
Copy pathdvi.c
File metadata and controls
executable file
·68 lines (62 loc) · 1.06 KB
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
63
64
65
66
67
68
/*
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/*
Module: implementation of DIV and MOD
Author: Ceriel J.H. Jacobs
Version: $Header$
Reason: We cannot use DVI and RMI, because DVI rounds towards 0
and Modula-2 requires truncation
*/
#include <em_abs.h>
int
dvi(j,i)
int j,i;
{
if (j == 0) TRP(EIDIVZ);
if ((i < 0) != (j < 0)) {
if (i < 0) i = -i;
else j = -j;
return -((i+j-1)/j);
}
else return i/j;
}
long
dvil(j,i)
long j,i;
{
if (j == 0) TRP(EIDIVZ);
if ((i < 0) != (j < 0)) {
if (i < 0) i = -i;
else j = -j;
return -((i+j-1)/j);
}
else return i/j;
}
int
rmi(j,i)
int j,i;
{
if (j == 0) TRP(EIDIVZ);
if (i == 0) return 0;
if ((i < 0) != (j < 0)) {
if (i < 0) i = -i;
else j = -j;
return j*((i+j-1)/j)-i;
}
else return i%j;
}
long
rmil(j,i)
long j,i;
{
if (j == 0) TRP(EIDIVZ);
if (i == 0) return 0L;
if ((i < 0) != (j < 0)) {
if (i < 0) i = -i;
else j = -j;
return j*((i+j-1)/j)-i;
}
else return i%j;
}