| 1 | /* s_ceill.c -- long double version of s_ceil.c. |
| 2 | * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz. |
| 3 | */ |
| 4 | |
| 5 | /* |
| 6 | * ==================================================== |
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
| 8 | * |
| 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 | * ==================================================== |
| 14 | */ |
| 15 | |
| 16 | #if defined(LIBM_SCCS) && !defined(lint) |
| 17 | static char rcsid[] = "$NetBSD: $" ; |
| 18 | #endif |
| 19 | |
| 20 | /* |
| 21 | * ceill(x) |
| 22 | * Return x rounded toward -inf to integral value |
| 23 | * Method: |
| 24 | * Bit twiddling. |
| 25 | */ |
| 26 | |
| 27 | #include <math.h> |
| 28 | #include <math_private.h> |
| 29 | |
| 30 | _Float128 __ceill(_Float128 x) |
| 31 | { |
| 32 | int64_t i0,i1,j0; |
| 33 | u_int64_t i,j; |
| 34 | GET_LDOUBLE_WORDS64(i0,i1,x); |
| 35 | j0 = ((i0>>48)&0x7fff)-0x3fff; |
| 36 | if(j0<48) { |
| 37 | if(j0<0) { |
| 38 | /* return 0*sign(x) if |x|<1 */ |
| 39 | if(i0<0) {i0=0x8000000000000000ULL;i1=0;} |
| 40 | else if((i0|i1)!=0) { i0=0x3fff000000000000ULL;i1=0;} |
| 41 | } else { |
| 42 | i = (0x0000ffffffffffffULL)>>j0; |
| 43 | if(((i0&i)|i1)==0) return x; /* x is integral */ |
| 44 | if(i0>0) i0 += (0x0001000000000000LL)>>j0; |
| 45 | i0 &= (~i); i1=0; |
| 46 | } |
| 47 | } else if (j0>111) { |
| 48 | if(j0==0x4000) return x+x; /* inf or NaN */ |
| 49 | else return x; /* x is integral */ |
| 50 | } else { |
| 51 | i = -1ULL>>(j0-48); |
| 52 | if((i1&i)==0) return x; /* x is integral */ |
| 53 | if(i0>0) { |
| 54 | if(j0==48) i0+=1; |
| 55 | else { |
| 56 | j = i1+(1LL<<(112-j0)); |
| 57 | if(j<i1) i0 +=1 ; /* got a carry */ |
| 58 | i1=j; |
| 59 | } |
| 60 | } |
| 61 | i1 &= (~i); |
| 62 | } |
| 63 | SET_LDOUBLE_WORDS64(x,i0,i1); |
| 64 | return x; |
| 65 | } |
| 66 | weak_alias (__ceill, ceill) |
| 67 | |