xref: /csrg-svn/lib/libc/quad/fixdfdi.c (revision 61159)
153436Sbostic /*-
2*61159Sbostic  * Copyright (c) 1992, 1993
3*61159Sbostic  *	The Regents of the University of California.  All rights reserved.
453436Sbostic  *
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  *
953436Sbostic  * %sccs.include.redist.c%
1053436Sbostic  */
1153436Sbostic 
1253436Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*61159Sbostic static char sccsid[] = "@(#)fixdfdi.c	8.1 (Berkeley) 06/04/93";
1453436Sbostic #endif /* LIBC_SCCS and not lint */
1553436Sbostic 
1653794Sbostic #include "quad.h"
1753459Sbostic 
1853794Sbostic /*
1953794Sbostic  * Convert double to (signed) quad.
2053794Sbostic  * We clamp anything that is out of range.
2153794Sbostic  */
2254431Sbostic quad_t
__fixdfdi(x)2354431Sbostic __fixdfdi(x)
2454431Sbostic 	double x;
2553436Sbostic {
2653794Sbostic 	if (x < 0)
2753794Sbostic 		if (x <= QUAD_MIN)
2853794Sbostic 			return (QUAD_MIN);
2953794Sbostic 		else
3054431Sbostic 			return ((quad_t)-(u_quad_t)-x);
3153794Sbostic 	else
3253794Sbostic 		if (x >= QUAD_MAX)
3353794Sbostic 			return (QUAD_MAX);
3453794Sbostic 		else
3554431Sbostic 			return ((quad_t)(u_quad_t)x);
3653436Sbostic }
37