Line 0
Link Here
|
|
|
1 |
/* @(#)s_logb.c 5.1 93/09/24 */ |
2 |
/* |
3 |
* ==================================================== |
4 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
5 |
* |
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 |
* ==================================================== |
11 |
*/ |
12 |
|
13 |
/* |
14 |
Copyright (C) 2005 Free Software Foundation, Inc. |
15 |
This file is part of the GNU C Library. |
16 |
|
17 |
The GNU C Library is free software; you can redistribute it and/or |
18 |
modify it under the terms of the GNU Lesser General Public |
19 |
License as published by the Free Software Foundation; either |
20 |
version 2.1 of the License, or (at your option) any later version. |
21 |
|
22 |
The GNU C Library is distributed in the hope that it will be useful, |
23 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
25 |
Lesser General Public License for more details. |
26 |
|
27 |
You should have received a copy of the GNU Lesser General Public |
28 |
License along with the GNU C Library; if not, write to the Free |
29 |
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
30 |
02111-1307 USA. */ |
31 |
|
32 |
#if defined(LIBM_SCCS) && !defined(lint) |
33 |
static char rcsid[] = "$NetBSD: s_logb.c,v 1.8 1995/05/10 20:47:50 jtc Exp $"; |
34 |
#endif |
35 |
|
36 |
/* |
37 |
* double logb(x) |
38 |
* IEEE 754 logb. Included to pass IEEE test suite. Not recommend. |
39 |
* Use ilogb instead. |
40 |
*/ |
41 |
|
42 |
#include "math.h" |
43 |
#include "math_private.h" |
44 |
#include <fenv.h> |
45 |
|
46 |
#ifdef __STDC__ |
47 |
double __logb(double x) |
48 |
#else |
49 |
double __logb(x) |
50 |
double x; |
51 |
#endif |
52 |
{ |
53 |
int32_t lx,ix; |
54 |
EXTRACT_WORDS(ix,lx,x); |
55 |
ix &= 0x7fffffff; /* high |x| */ |
56 |
if((ix|lx)==0) return -1.0/fabs(x); |
57 |
if(ix>=0x7ff00000) return x*x; |
58 |
if((ix>>=20)==0) /* IEEE 754 logb */ |
59 |
return -1022.0; |
60 |
else |
61 |
{ |
62 |
double result; |
63 |
int round_mode = fegetround(); |
64 |
fesetround(FE_TONEAREST); |
65 |
result = (double) (ix-1023); |
66 |
fesetround(round_mode); |
67 |
return result; |
68 |
} |
69 |
} |
70 |
weak_alias (__logb, logb) |
71 |
#ifdef NO_LONG_DOUBLE |
72 |
strong_alias (__logb, __logbl) |
73 |
weak_alias (__logb, logbl) |
74 |
#endif |