s_logb.c revision 1.6 1 1.1 jtc /* @(#)s_logb.c 5.1 93/09/24 */
2 1.1 jtc /*
3 1.1 jtc * ====================================================
4 1.1 jtc * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 1.1 jtc *
6 1.1 jtc * Developed at SunPro, a Sun Microsystems, Inc. business.
7 1.1 jtc * Permission to use, copy, modify, and distribute this
8 1.1 jtc * software is freely granted, provided that this notice
9 1.1 jtc * is preserved.
10 1.1 jtc * ====================================================
11 1.1 jtc */
12 1.3 jtc
13 1.3 jtc #ifndef lint
14 1.6 jtc static char rcsid[] = "$Id: s_logb.c,v 1.6 1994/08/18 23:07:04 jtc Exp $";
15 1.3 jtc #endif
16 1.1 jtc
17 1.1 jtc /*
18 1.1 jtc * double logb(x)
19 1.1 jtc * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
20 1.1 jtc * Use ilogb instead.
21 1.1 jtc */
22 1.1 jtc
23 1.5 jtc #include "math.h"
24 1.5 jtc #include "math_private.h"
25 1.1 jtc
26 1.1 jtc #ifdef __STDC__
27 1.1 jtc double logb(double x)
28 1.1 jtc #else
29 1.1 jtc double logb(x)
30 1.1 jtc double x;
31 1.1 jtc #endif
32 1.1 jtc {
33 1.6 jtc int32_t lx,ix;
34 1.5 jtc EXTRACT_WORDS(ix,lx,x);
35 1.5 jtc ix &= 0x7fffffff; /* high |x| */
36 1.1 jtc if((ix|lx)==0) return -1.0/fabs(x);
37 1.1 jtc if(ix>=0x7ff00000) return x*x;
38 1.1 jtc if((ix>>=20)==0) /* IEEE 754 logb */
39 1.1 jtc return -1022.0;
40 1.1 jtc else
41 1.1 jtc return (double) (ix-1023);
42 1.1 jtc }
43