summaryrefslogtreecommitdiffstats
path: root/config/auto-aux/divmod.c
blob: e85e4b3fc1b7419eed82a704455a49e8a9bcee0a (plain)
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
/***********************************************************************/
/*                                                                     */
/*                                OCaml                                */
/*                                                                     */
/*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 1996 Institut National de Recherche en Informatique et   */
/*  en Automatique.  All rights reserved.  This file is distributed    */
/*  under the terms of the GNU Library General Public License, with    */
/*  the special exception on linking described in file ../../LICENSE.  */
/*                                                                     */
/***********************************************************************/

/* Test semantics of division and modulus for negative arguments */

long div4[] =
{ -4,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1,-1,-1,0,0,0,
  0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4 };

long divm4[] =
{ 4,3,3,3,3,2,2,2,2,1,1,1,1,0,0,0,
  0,0,0,0,-1,-1,-1,-1,-2,-2,-2,-2,-3,-3,-3,-3,-4 };

long mod4[] =
{ 0,-3,-2,-1,0,-3,-2,-1,0,-3,-2,-1,0,-3,-2,-1,
  0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0 };

long modm4[] =
{ 0,-3,-2,-1,0,-3,-2,-1,0,-3,-2,-1,0,-3,-2,-1,
  0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0 };

long q1 = 4;
long q2 = -4;

int main()
{
  int i;
  for (i = -16; i <= 16; i++) {
    if (i / q1 != div4[i+16]) return 1;
    if (i / q2 != divm4[i+16]) return 1;
    if (i % q1 != mod4[i+16]) return 1;
    if (i % q2 != modm4[i+16]) return 1;
  }
  return 0;
}