Wunused-var-15.c: Add -fno-common additional option on hppa*-*-hpux*.
[official-gcc.git] / libquadmath / math / floorq.c
blob0d74f94e27d015d65bcfa702de0b41e07d65160c
1 /* floorq.c -- __float128 version of s_floor.c.
2 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
3 */
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
16 #include "quadmath-imp.h"
18 static const __float128 huge = 1.0e4930Q;
20 __float128
21 floorq (__float128 x)
23 int64_t i0,i1,j0;
24 uint64_t i,j;
25 GET_FLT128_WORDS64(i0,i1,x);
26 j0 = ((i0>>48)&0x7fff)-0x3fff;
27 if(j0<48) {
28 if(j0<0) { /* raise inexact if x != 0 */
29 if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
30 if(i0>=0) {i0=i1=0;}
31 else if(((i0&0x7fffffffffffffffLL)|i1)!=0)
32 { i0=0xbfff000000000000ULL;i1=0;}
34 } else {
35 i = (0x0000ffffffffffffULL)>>j0;
36 if(((i0&i)|i1)==0) return x; /* x is integral */
37 if(huge+x>0.0) { /* raise inexact flag */
38 if(i0<0) i0 += (0x0001000000000000LL)>>j0;
39 i0 &= (~i); i1=0;
42 } else if (j0>111) {
43 if(j0==0x4000) return x+x; /* inf or NaN */
44 else return x; /* x is integral */
45 } else {
46 i = -1ULL>>(j0-48);
47 if((i1&i)==0) return x; /* x is integral */
48 if(huge+x>0.0) { /* raise inexact flag */
49 if(i0<0) {
50 if(j0==48) i0+=1;
51 else {
52 j = i1+(1LL<<(112-j0));
53 if(j<i1) i0 +=1 ; /* got a carry */
54 i1=j;
57 i1 &= (~i);
60 SET_FLT128_WORDS64(x,i0,i1);
61 return x;