Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / ieee754 / ldbl-96 / s_modfl.c
blobe9401d0f5dc4226223646e1ffd95c0cb5f957678
1 /* s_modfl.c -- long double version of s_modf.c.
2 * Conversion to long double by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
4 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
18 * modfl(long double x, long double *iptr)
19 * return fraction part of x, and return x's integral part in *iptr.
20 * Method:
21 * Bit twiddling.
23 * Exception:
24 * No exception.
27 #include <math.h>
28 #include <math_private.h>
30 static const long double one = 1.0;
32 long double
33 __modfl(long double x, long double *iptr)
35 int32_t i0,i1,j0;
36 u_int32_t i,se;
37 GET_LDOUBLE_WORDS(se,i0,i1,x);
38 j0 = (se&0x7fff)-0x3fff; /* exponent of x */
39 if(j0<32) { /* integer part in high x */
40 if(j0<0) { /* |x|<1 */
41 SET_LDOUBLE_WORDS(*iptr,se&0x8000,0,0); /* *iptr = +-0 */
42 return x;
43 } else {
44 i = (0x7fffffff)>>j0;
45 if(((i0&i)|i1)==0) { /* x is integral */
46 *iptr = x;
47 SET_LDOUBLE_WORDS(x,se&0x8000,0,0); /* return +-0 */
48 return x;
49 } else {
50 SET_LDOUBLE_WORDS(*iptr,se,i0&(~i),0);
51 return x - *iptr;
54 } else if (__builtin_expect(j0>63, 0)) { /* no fraction part */
55 *iptr = x*one;
56 /* We must handle NaNs separately. */
57 if (j0 == 0x4000 && ((i0 & 0x7fffffff) | i1))
58 return x*one;
59 SET_LDOUBLE_WORDS(x,se&0x8000,0,0); /* return +-0 */
60 return x;
61 } else { /* fraction part in low x */
62 i = ((u_int32_t)(0x7fffffff))>>(j0-32);
63 if((i1&i)==0) { /* x is integral */
64 *iptr = x;
65 SET_LDOUBLE_WORDS(x,se&0x8000,0,0); /* return +-0 */
66 return x;
67 } else {
68 SET_LDOUBLE_WORDS(*iptr,se,i0,i1&(~i));
69 return x - *iptr;
73 weak_alias (__modfl, modfl)