xref: /csrg-svn/lib/libc/quad/subdi3.c (revision 61160)
153444Sbostic /*-
2*61160Sbostic  * Copyright (c) 1992, 1993
3*61160Sbostic  *	The Regents of the University of California.  All rights reserved.
453444Sbostic  *
553794Sbostic  * This software was developed by the Computer Systems Engineering group
653794Sbostic  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
753794Sbostic  * contributed to Berkeley.
853794Sbostic  *
953444Sbostic  * %sccs.include.redist.c%
1053444Sbostic  */
1153444Sbostic 
1253444Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*61160Sbostic static char sccsid[] = "@(#)subdi3.c	8.1 (Berkeley) 06/04/93";
1453444Sbostic #endif /* LIBC_SCCS and not lint */
1553444Sbostic 
1653794Sbostic #include "quad.h"
1753459Sbostic 
1853794Sbostic /*
1953794Sbostic  * Subtract two quad values.  This is trivial since a one-bit carry
2053794Sbostic  * from a single u_long difference x-y occurs if and only if (x-y) > x.
2153794Sbostic  */
2254431Sbostic quad_t
__subdi3(a,b)2354431Sbostic __subdi3(a, b)
2454431Sbostic 	quad_t a, b;
2553444Sbostic {
2653794Sbostic 	union uu aa, bb, diff;
2753444Sbostic 
2853794Sbostic 	aa.q = a;
2953794Sbostic 	bb.q = b;
3053794Sbostic 	diff.ul[L] = aa.ul[L] - bb.ul[L];
3153794Sbostic 	diff.ul[H] = aa.ul[H] - bb.ul[H] - (diff.ul[L] > aa.ul[L]);
3253794Sbostic 	return (diff.q);
3353444Sbostic }
34