source: trunk/minix/lib/ack/libm2/dvi.c@ 20

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

Minix 3.1.2a

File size: 1.1 KB
Line 
1/*
2 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 See the copyright notice in the ACK home directory, in the file "Copyright".
4*/
5
6/*
7 Module: implementation of DIV and MOD
8 Author: Ceriel J.H. Jacobs
9 Version: $Header: /cvsup/minix/src/lib/ack/libm2/dvi.c,v 1.1 2005/10/10 15:27:46 beng Exp $
10 Reason: We cannot use DVI and RMI, because DVI rounds towards 0
11 and Modula-2 requires truncation
12*/
13
14#include <em_abs.h>
15
16int
17dvi(j,i)
18 int j,i;
19{
20 if (j == 0) TRP(EIDIVZ);
21 if ((i < 0) != (j < 0)) {
22 if (i < 0) i = -i;
23 else j = -j;
24 return -((i+j-1)/j);
25 }
26 else return i/j;
27}
28
29long
30dvil(j,i)
31 long j,i;
32{
33 if (j == 0) TRP(EIDIVZ);
34 if ((i < 0) != (j < 0)) {
35 if (i < 0) i = -i;
36 else j = -j;
37 return -((i+j-1)/j);
38 }
39 else return i/j;
40}
41
42int
43rmi(j,i)
44 int j,i;
45{
46 if (j == 0) TRP(EIDIVZ);
47 if (i == 0) return 0;
48 if ((i < 0) != (j < 0)) {
49 if (i < 0) i = -i;
50 else j = -j;
51 return j*((i+j-1)/j)-i;
52 }
53 else return i%j;
54}
55
56long
57rmil(j,i)
58 long j,i;
59{
60 if (j == 0) TRP(EIDIVZ);
61 if (i == 0) return 0L;
62 if ((i < 0) != (j < 0)) {
63 if (i < 0) i = -i;
64 else j = -j;
65 return j*((i+j-1)/j)-i;
66 }
67 else return i%j;
68}
Note: See TracBrowser for help on using the repository browser.