Update copyright notices with scripts/update-copyrights.
[glibc.git] / sysdeps / ieee754 / dbl-64 / wordsize-64 / s_modf.c
blob89743168cb573f8ad36697d4a1811bf1cf3bde0a
1 /* Rewritten for 64-bit machines by Ulrich Drepper <drepper@gmail.com>. */
2 /*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
9 * is preserved.
10 * ====================================================
14 * modf(double x, double *iptr)
15 * return fraction part of x, and return x's integral part in *iptr.
16 * Method:
17 * Bit twiddling.
19 * Exception:
20 * No exception.
23 #include <math.h>
24 #include <math_private.h>
26 static const double one = 1.0;
28 double
29 __modf(double x, double *iptr)
31 int64_t i0;
32 int32_t j0;
33 EXTRACT_WORDS64(i0,x);
34 j0 = ((i0>>52)&0x7ff)-0x3ff; /* exponent of x */
35 if(j0<52) { /* integer part in x */
36 if(j0<0) { /* |x|<1 */
37 /* *iptr = +-0 */
38 INSERT_WORDS64(*iptr,i0&UINT64_C(0x8000000000000000));
39 return x;
40 } else {
41 uint64_t i = UINT64_C(0x000fffffffffffff)>>j0;
42 if((i0&i)==0) { /* x is integral */
43 *iptr = x;
44 /* return +-0 */
45 INSERT_WORDS64(x,i0&UINT64_C(0x8000000000000000));
46 return x;
47 } else {
48 INSERT_WORDS64(*iptr,i0&(~i));
49 return x - *iptr;
52 } else { /* no fraction part */
53 *iptr = x*one;
54 /* We must handle NaNs separately. */
55 if (j0 == 0x400 && (i0 & UINT64_C(0xfffffffffffff)))
56 return x*one;
57 INSERT_WORDS64(x,i0&UINT64_C(0x8000000000000000)); /* return +-0 */
58 return x;
61 weak_alias (__modf, modf)
62 #ifdef NO_LONG_DOUBLE
63 strong_alias (__modf, __modfl)
64 weak_alias (__modf, modfl)
65 #endif