Fix sin, sincos missing underflows (bug 16526, bug 16538).
[glibc.git] / sysdeps / ieee754 / dbl-64 / s_frexp.c
blob1b8d8500ba89909319c05556ba79ce14593b1e28
1 /* @(#)s_frexp.c 5.1 93/09/24 */
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 * ====================================================
13 #if defined(LIBM_SCCS) && !defined(lint)
14 static char rcsid[] = "$NetBSD: s_frexp.c,v 1.9 1995/05/10 20:47:24 jtc Exp $";
15 #endif
18 * for non-zero x
19 * x = frexp(arg,&exp);
20 * return a double fp quantity x such that 0.5 <= |x| <1.0
21 * and the corresponding binary exponent "exp". That is
22 * arg = x*2^exp.
23 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
24 * with *exp=0.
27 #include <math.h>
28 #include <math_private.h>
30 static const double
31 two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
33 double
34 __frexp (double x, int *eptr)
36 int32_t hx, ix, lx;
37 EXTRACT_WORDS (hx, lx, x);
38 ix = 0x7fffffff & hx;
39 *eptr = 0;
40 if (ix >= 0x7ff00000 || ((ix | lx) == 0))
41 return x; /* 0,inf,nan */
42 if (ix < 0x00100000) /* subnormal */
44 x *= two54;
45 GET_HIGH_WORD (hx, x);
46 ix = hx & 0x7fffffff;
47 *eptr = -54;
49 *eptr += (ix >> 20) - 1022;
50 hx = (hx & 0x800fffff) | 0x3fe00000;
51 SET_HIGH_WORD (x, hx);
52 return x;
54 weak_alias (__frexp, frexp)
55 #ifdef NO_LONG_DOUBLE
56 strong_alias (__frexp, __frexpl)
57 weak_alias (__frexp, frexpl)
58 #endif