added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / compiler / mlib / s_frexp.c
blobd89e135f0990a4be22c6284b8aa570d5ffaaf110
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 #ifndef lint
14 static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_frexp.c,v 1.10 2005/03/07 21:27:37 das 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 <sys/cdefs.h>
28 #include <float.h>
30 #include "math.h"
31 #include "math_private.h"
33 static const double
34 two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
36 double
37 frexp(double x, int *eptr)
39 int32_t hx, ix, lx;
40 EXTRACT_WORDS(hx,lx,x);
41 ix = 0x7fffffff&hx;
42 *eptr = 0;
43 if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
44 if (ix<0x00100000) { /* subnormal */
45 x *= two54;
46 GET_HIGH_WORD(hx,x);
47 ix = hx&0x7fffffff;
48 *eptr = -54;
50 *eptr += (ix>>20)-1022;
51 hx = (hx&0x800fffff)|0x3fe00000;
52 SET_HIGH_WORD(x,hx);
53 return x;
56 #if (LDBL_MANT_DIG == 53)
57 __weak_reference(frexp, frexpl);
58 #endif