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[] = "@(#)fixunsdfdi.c 5.1 (Berkeley) 05/12/92"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include "longlong.h" 13 14 #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD) 15 16 long long 17 __fixunsdfdi (a) 18 double a; 19 { 20 double b; 21 unsigned long long v; 22 23 if (a < 0) 24 return 0; 25 26 /* Compute high word of result, as a flonum. */ 27 b = (a / HIGH_WORD_COEFF); 28 /* Convert that to fixed (but not to long long!), 29 and shift it into the high word. */ 30 v = (unsigned long int) b; 31 v <<= BITS_PER_WORD; 32 /* Remove high part from the double, leaving the low part as flonum. */ 33 a -= (double)v; 34 /* Convert that to fixed (but not to long long!) and add it in. 35 Sometimes A comes out negative. This is significant, since 36 A has more bits than a long int does. */ 37 if (a < 0) 38 v -= (unsigned long int) (- a); 39 else 40 v += (unsigned long int) a; 41 return v; 42 } 43