blob: ec777fd2627701d520dc3e2b2fc48fc4bd6a5578 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
10 */
11
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080012/*
13 * double logb(x)
14 * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
15 * Use ilogb instead.
16 */
17
Elliott Hughesa0ee0782013-01-30 19:06:37 -080018#include <float.h>
19
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080020#include "math.h"
21#include "math_private.h"
22
23static const double
24two54 = 1.80143985094819840000e+16; /* 43500000 00000000 */
25
26double
27logb(double x)
28{
29 int32_t lx,ix;
30 EXTRACT_WORDS(ix,lx,x);
31 ix &= 0x7fffffff; /* high |x| */
32 if((ix|lx)==0) return -1.0/fabs(x);
33 if(ix>=0x7ff00000) return x*x;
34 if(ix<0x00100000) {
35 x *= two54; /* convert subnormal x to normal */
Jack Ren1fa7b452012-02-28 12:02:21 +080036 GET_HIGH_WORD(ix,x);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037 ix &= 0x7fffffff;
Jack Ren1fa7b452012-02-28 12:02:21 +080038 return (double) ((ix>>20)-1023-54);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080039 } else
40 return (double) ((ix>>20)-1023);
41}
Elliott Hughesa0ee0782013-01-30 19:06:37 -080042
43#if (LDBL_MANT_DIG == 53)
44__weak_reference(logb, logbl);
45#endif