Don't use __glibcxx_assert to check class invariants
[official-gcc.git] / libquadmath / math / floorq.c
blob41b993fa7a0c75ae57a1f445d733c8ee9d74c88e
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 __float128
19 floorq (__float128 x)
21 int64_t i0,i1,j0;
22 uint64_t i,j;
23 GET_FLT128_WORDS64(i0,i1,x);
24 j0 = ((i0>>48)&0x7fff)-0x3fff;
25 if(j0<48) {
26 if(j0<0) {
27 /* return 0*sign(x) if |x|<1 */
28 if(i0>=0) {i0=i1=0;}
29 else if(((i0&0x7fffffffffffffffLL)|i1)!=0)
30 { i0=0xbfff000000000000ULL;i1=0;}
31 } else {
32 i = (0x0000ffffffffffffULL)>>j0;
33 if(((i0&i)|i1)==0) return x; /* x is integral */
34 if(i0<0) i0 += (0x0001000000000000LL)>>j0;
35 i0 &= (~i); i1=0;
37 } else if (j0>111) {
38 if(j0==0x4000) return x+x; /* inf or NaN */
39 else return x; /* x is integral */
40 } else {
41 i = -1ULL>>(j0-48);
42 if((i1&i)==0) return x; /* x is integral */
43 if(i0<0) {
44 if(j0==48) i0+=1;
45 else {
46 j = i1+(1LL<<(112-j0));
47 if(j<i1) i0 +=1 ; /* got a carry */
48 i1=j;
51 i1 &= (~i);
53 SET_FLT128_WORDS64(x,i0,i1);
54 return x;