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 */
5
6/*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 *
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 * ====================================================
15 */
16
17/*
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.
22 *
23 * Exception:
24 * No exception.
25 */
26
27#include <math.h>
28#include <math_private.h>
29#include <libm-alias-ldouble.h>
30
31static const long double one = 1.0;
32
33long double
34__modfl(long double x, long double *iptr)
35{
36 int32_t i0,i1,j0;
37 uint32_t i,se;
38 GET_LDOUBLE_WORDS(se,i0,i1,x);
39 j0 = (se&0x7fff)-0x3fff; /* exponent of x */
40 if(j0<32) { /* integer part in high x */
41 if(j0<0) { /* |x|<1 */
42 SET_LDOUBLE_WORDS(*iptr,se&0x8000,0,0); /* *iptr = +-0 */
43 return x;
44 } else {
45 i = (0x7fffffff)>>j0;
46 if(((i0&i)|i1)==0) { /* x is integral */
47 *iptr = x;
48 SET_LDOUBLE_WORDS(x,se&0x8000,0,0); /* return +-0 */
49 return x;
50 } else {
51 SET_LDOUBLE_WORDS(*iptr,se,i0&(~i),0);
52 return x - *iptr;
53 }
54 }
55 } else if (__builtin_expect(j0>63, 0)) { /* no fraction part */
56 *iptr = x*one;
57 /* We must handle NaNs separately. */
58 if (j0 == 0x4000 && ((i0 & 0x7fffffff) | i1))
59 return x*one;
60 SET_LDOUBLE_WORDS(x,se&0x8000,0,0); /* return +-0 */
61 return x;
62 } else { /* fraction part in low x */
63 i = ((uint32_t)(0x7fffffff))>>(j0-32);
64 if((i1&i)==0) { /* x is integral */
65 *iptr = x;
66 SET_LDOUBLE_WORDS(x,se&0x8000,0,0); /* return +-0 */
67 return x;
68 } else {
69 SET_LDOUBLE_WORDS(*iptr,se,i0,i1&(~i));
70 return x - *iptr;
71 }
72 }
73}
74libm_alias_ldouble (__modf, modf)
75