153436Sbostic /*- 253436Sbostic * Copyright (c) 1992 The Regents of the University of California. 353436Sbostic * All rights reserved. 453436Sbostic * 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 * 953436Sbostic * %sccs.include.redist.c% 1053436Sbostic */ 1153436Sbostic 1253436Sbostic #if defined(LIBC_SCCS) && !defined(lint) 13*53794Sbostic static char sccsid[] = "@(#)fixdfdi.c 5.3 (Berkeley) 06/02/92"; 1453436Sbostic #endif /* LIBC_SCCS and not lint */ 1553436Sbostic 16*53794Sbostic #include "quad.h" 1753459Sbostic 18*53794Sbostic #ifndef QUAD_MAX /* should be in <limits.h> maybe? */ 19*53794Sbostic #define QUAD_MAX ((quad)(((u_quad)1 << (QUAD_BITS - 1)) - 1)) 20*53794Sbostic #define QUAD_MIN (-QUAD_MAX - 1) 21*53794Sbostic #endif 2253459Sbostic 23*53794Sbostic /* 24*53794Sbostic * Convert double to (signed) quad. 25*53794Sbostic * We clamp anything that is out of range. 26*53794Sbostic */ 27*53794Sbostic quad 28*53794Sbostic __fixdfdi(double x) 2953436Sbostic { 30*53794Sbostic if (x < 0) 31*53794Sbostic if (x <= QUAD_MIN) 32*53794Sbostic return (QUAD_MIN); 33*53794Sbostic else 34*53794Sbostic return ((quad)-(u_quad)-x); 35*53794Sbostic else 36*53794Sbostic if (x >= QUAD_MAX) 37*53794Sbostic return (QUAD_MAX); 38*53794Sbostic else 39*53794Sbostic return ((quad)(u_quad)x); 4053436Sbostic } 41