xref: /csrg-svn/lib/libc/quad/floatdidf.c (revision 53438)
1 /*-
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)floatdidf.c	5.1 (Berkeley) 05/12/92";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include "longlong.h"
13 
14 #define HIGH_HALFWORD_COEFF (((long long) 1) << (BITS_PER_WORD / 2))
15 #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
16 
17 double
18 __floatdidf (u)
19      long long u;
20 {
21   double d;
22   int negate = 0;
23 
24   if (u < 0)
25     u = -u, negate = 1;
26 
27   d = (unsigned int) (u >> BITS_PER_WORD);
28   d *= HIGH_HALFWORD_COEFF;
29   d *= HIGH_HALFWORD_COEFF;
30   d += (unsigned int) (u & (HIGH_WORD_COEFF - 1));
31 
32   return (negate ? -d : d);
33 }
34