xref: /csrg-svn/lib/libc/quad/TESTS/divrem.c (revision 53797)
1*53797Sbostic /*-
2*53797Sbostic  * Copyright (c) 1992 The Regents of the University of California.
3*53797Sbostic  * All rights reserved.
4*53797Sbostic  *
5*53797Sbostic  * This software was developed by the Computer Systems Engineering group
6*53797Sbostic  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7*53797Sbostic  * contributed to Berkeley.
8*53797Sbostic  *
9*53797Sbostic  * %sccs.include.redist.c%
10*53797Sbostic  */
11*53797Sbostic 
12*53797Sbostic #ifndef lint
13*53797Sbostic char copyright[] =
14*53797Sbostic "@(#) Copyright (c) 1992 The Regents of the University of California.\n\
15*53797Sbostic  All rights reserved.\n";
16*53797Sbostic #endif /* not lint */
17*53797Sbostic 
18*53797Sbostic #ifndef lint
19*53797Sbostic static char sccsid[] = "@(#)divrem.c	5.1 (Berkeley) 06/02/92";
20*53797Sbostic #endif /* not lint */
21*53797Sbostic 
22*53797Sbostic #include <stdio.h>
23*53797Sbostic 
24*53797Sbostic main()
25*53797Sbostic {
26*53797Sbostic 	union { long long q; unsigned long v[2]; } a, b, q, r;
27*53797Sbostic 	char buf[300];
28*53797Sbostic 	extern long long __qdivrem(unsigned long long, unsigned long long,
29*53797Sbostic 	    unsigned long long *);
30*53797Sbostic 
31*53797Sbostic 	for (;;) {
32*53797Sbostic 		printf("> ");
33*53797Sbostic 		if (fgets(buf, sizeof buf, stdin) == NULL)
34*53797Sbostic 			break;
35*53797Sbostic 		if (sscanf(buf, "%lu:%lu %lu:%lu",
36*53797Sbostic 			    &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4 &&
37*53797Sbostic 		    sscanf(buf, "0x%lx:%lx 0x%lx:%lx",
38*53797Sbostic 			    &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4) {
39*53797Sbostic 			printf("eh?\n");
40*53797Sbostic 			continue;
41*53797Sbostic 		}
42*53797Sbostic 		q.q = __qdivrem(a.q, b.q, &r.q);
43*53797Sbostic 		printf("%lx:%lx /%% %lx:%lx => q=%lx:%lx r=%lx:%lx\n",
44*53797Sbostic 		    a.v[0], a.v[1], b.v[0], b.v[1],
45*53797Sbostic 		    q.v[0], q.v[1], r.v[0], r.v[1]);
46*53797Sbostic 		printf("  = %lX%08lX / %lX%08lX => %lX%08lX\n\
47*53797Sbostic   = %lX%08lX %% %lX%08lX => %lX%08lX\n",
48*53797Sbostic 		    a.v[0], a.v[1], b.v[0], b.v[1], q.v[0], q.v[1],
49*53797Sbostic 		    a.v[0], a.v[1], b.v[0], b.v[1], r.v[0], r.v[1]);
50*53797Sbostic 	}
51*53797Sbostic 	exit(0);
52*53797Sbostic }
53