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.2 (Berkeley) 05/12/92"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 /* Copyright (C) 1989, 1992 Free Software Foundation, Inc. 13 14 This file is part of GNU CC. 15 16 GNU CC is free software; you can redistribute it and/or modify 17 it under the terms of the GNU General Public License as published by 18 the Free Software Foundation; either version 2, or (at your option) 19 any later version. 20 21 GNU CC is distributed in the hope that it will be useful, 22 but WITHOUT ANY WARRANTY; without even the implied warranty of 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 GNU General Public License for more details. 25 26 You should have received a copy of the GNU General Public License 27 along with GNU CC; see the file COPYING. If not, write to 28 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 29 30 /* As a special exception, if you link this library with files 31 compiled with GCC to produce an executable, this does not cause 32 the resulting executable to be covered by the GNU General Public License. 33 This exception does not however invalidate any other reasons why 34 the executable file might be covered by the GNU General Public License. */ 35 36 #include "longlong.h" 37 38 #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD) 39 40 long long 41 __fixunsdfdi (a) 42 double a; 43 { 44 double b; 45 unsigned long long v; 46 47 if (a < 0) 48 return 0; 49 50 /* Compute high word of result, as a flonum. */ 51 b = (a / HIGH_WORD_COEFF); 52 /* Convert that to fixed (but not to long long!), 53 and shift it into the high word. */ 54 v = (unsigned long int) b; 55 v <<= BITS_PER_WORD; 56 /* Remove high part from the double, leaving the low part as flonum. */ 57 a -= (double)v; 58 /* Convert that to fixed (but not to long long!) and add it in. 59 Sometimes A comes out negative. This is significant, since 60 A has more bits than a long int does. */ 61 if (a < 0) 62 v -= (unsigned long int) (- a); 63 else 64 v += (unsigned long int) a; 65 return v; 66 } 67