The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 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 Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 12 | /* |
| 13 | * double logb(x) |
| 14 | * IEEE 754 logb. Included to pass IEEE test suite. Not recommend. |
| 15 | * Use ilogb instead. |
| 16 | */ |
| 17 | |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 18 | #include <float.h> |
| 19 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 20 | #include "math.h" |
| 21 | #include "math_private.h" |
| 22 | |
| 23 | static const double |
| 24 | two54 = 1.80143985094819840000e+16; /* 43500000 00000000 */ |
| 25 | |
| 26 | double |
| 27 | logb(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 Ren | 1fa7b45 | 2012-02-28 12:02:21 +0800 | [diff] [blame] | 36 | GET_HIGH_WORD(ix,x); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | ix &= 0x7fffffff; |
Jack Ren | 1fa7b45 | 2012-02-28 12:02:21 +0800 | [diff] [blame] | 38 | return (double) ((ix>>20)-1023-54); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 39 | } else |
| 40 | return (double) ((ix>>20)-1023); |
| 41 | } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 42 | |
| 43 | #if (LDBL_MANT_DIG == 53) |
| 44 | __weak_reference(logb, logbl); |
| 45 | #endif |