xref: /csrg-svn/lib/libc/quad/subdi3.c (revision 53794)
153444Sbostic /*-
253444Sbostic  * Copyright (c) 1992 The Regents of the University of California.
353444Sbostic  * All rights reserved.
453444Sbostic  *
5*53794Sbostic  * This software was developed by the Computer Systems Engineering group
6*53794Sbostic  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7*53794Sbostic  * contributed to Berkeley.
8*53794Sbostic  *
953444Sbostic  * %sccs.include.redist.c%
1053444Sbostic  */
1153444Sbostic 
1253444Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*53794Sbostic static char sccsid[] = "@(#)subdi3.c	5.4 (Berkeley) 06/02/92";
1453444Sbostic #endif /* LIBC_SCCS and not lint */
1553444Sbostic 
16*53794Sbostic #include "quad.h"
1753459Sbostic 
18*53794Sbostic /*
19*53794Sbostic  * Subtract two quad values.  This is trivial since a one-bit carry
20*53794Sbostic  * from a single u_long difference x-y occurs if and only if (x-y) > x.
21*53794Sbostic  */
22*53794Sbostic quad
23*53794Sbostic __subdi3(quad a, quad b)
2453444Sbostic {
25*53794Sbostic 	union uu aa, bb, diff;
2653444Sbostic 
27*53794Sbostic 	aa.q = a;
28*53794Sbostic 	bb.q = b;
29*53794Sbostic 	diff.ul[L] = aa.ul[L] - bb.ul[L];
30*53794Sbostic 	diff.ul[H] = aa.ul[H] - bb.ul[H] - (diff.ul[L] > aa.ul[L]);
31*53794Sbostic 	return (diff.q);
3253444Sbostic }
33