source: trunk/sys/libm/s_logb.c @ 238

Last change on this file since 238 was 1, checked in by alain, 8 years ago

First import

File size: 1022 bytes
Line 
1
2/* @(#)s_logb.c 5.1 93/09/24 */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14/*
15 * double logb(x)
16 * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
17 * Use ilogb instead.
18 */
19
20#include <libm/fdlibm.h>
21
22#ifdef __STDC__
23static const double one = 1.0;
24#else
25static double one = 1.0;
26#endif
27
28#ifdef __STDC__
29        double logb(double x)
30#else
31        double logb(x)
32        double x;
33#endif
34{
35        int n0,lx,ix;
36        n0 = ((*(int*)&one)>>29)^1;
37        ix = (*(n0+(int*)&x))&0x7fffffff;       /* high |x| */
38        lx = *(1-n0+(int*)&x);                  /* low x */
39        if((ix|lx)==0) return -1.0/fabs(x);
40        if(ix>=0x7ff00000) return x*x;
41        if((ix>>=20)==0)                        /* IEEE 754 logb */
42                return -1022.0; 
43        else
44                return (double) (ix-1023); 
45}
Note: See TracBrowser for help on using the repository browser.