|
Packit |
6c4009 |
/* s_ceill.c -- long double version of s_ceil.c.
|
|
Packit |
6c4009 |
* Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
6c4009 |
* software is freely granted, provided that this notice
|
|
Packit |
6c4009 |
* is preserved.
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit Service |
3b0880 |
#if defined(LIBM_SCCS) && !defined(lint)
|
|
Packit |
6c4009 |
static char rcsid[] = "$NetBSD: $";
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ceill(x)
|
|
Packit |
6c4009 |
* Return x rounded toward -inf to integral value
|
|
Packit |
6c4009 |
* Method:
|
|
Packit |
6c4009 |
* Bit twiddling.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
#include <libm-alias-ldouble.h>
|
|
Packit |
6c4009 |
|
|
Packit Service |
3b0880 |
_Float128 __ceill(_Float128 x)
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
3b0880 |
int64_t i0,i1,j0;
|
|
Packit Service |
3b0880 |
uint64_t i,j;
|
|
Packit Service |
3b0880 |
GET_LDOUBLE_WORDS64(i0,i1,x);
|
|
Packit Service |
3b0880 |
j0 = ((i0>>48)&0x7fff)-0x3fff;
|
|
Packit Service |
3b0880 |
if(j0<48) {
|
|
Packit Service |
3b0880 |
if(j0<0) {
|
|
Packit Service |
3b0880 |
/* return 0*sign(x) if |x|<1 */
|
|
Packit Service |
3b0880 |
if(i0<0) {i0=0x8000000000000000ULL;i1=0;}
|
|
Packit Service |
3b0880 |
else if((i0|i1)!=0) { i0=0x3fff000000000000ULL;i1=0;}
|
|
Packit Service |
3b0880 |
} else {
|
|
Packit Service |
3b0880 |
i = (0x0000ffffffffffffULL)>>j0;
|
|
Packit Service |
3b0880 |
if(((i0&i)|i1)==0) return x; /* x is integral */
|
|
Packit Service |
3b0880 |
if(i0>0) i0 += (0x0001000000000000LL)>>j0;
|
|
Packit Service |
3b0880 |
i0 &= (~i); i1=0;
|
|
Packit |
6c4009 |
}
|
|
Packit Service |
3b0880 |
} else if (j0>111) {
|
|
Packit Service |
3b0880 |
if(j0==0x4000) return x+x; /* inf or NaN */
|
|
Packit Service |
3b0880 |
else return x; /* x is integral */
|
|
Packit Service |
3b0880 |
} else {
|
|
Packit Service |
3b0880 |
i = -1ULL>>(j0-48);
|
|
Packit Service |
3b0880 |
if((i1&i)==0) return x; /* x is integral */
|
|
Packit Service |
3b0880 |
if(i0>0) {
|
|
Packit Service |
3b0880 |
if(j0==48) i0+=1;
|
|
Packit Service |
3b0880 |
else {
|
|
Packit Service |
3b0880 |
j = i1+(1LL<<(112-j0));
|
|
Packit Service |
3b0880 |
if(j
|
|
Packit Service |
3b0880 |
i1=j;
|
|
Packit Service |
3b0880 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit Service |
3b0880 |
i1 &= (~i);
|
|
Packit |
6c4009 |
}
|
|
Packit Service |
3b0880 |
SET_LDOUBLE_WORDS64(x,i0,i1);
|
|
Packit Service |
3b0880 |
return x;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
libm_alias_ldouble (__ceil, ceil)
|