| 1 |
/** |
| 2 |
* This file has no copyright assigned and is placed in the Public Domain. |
| 3 |
* This file is part of the mingw-w64 runtime package. |
| 4 |
* No warranty is given; refer to the file DISCLAIMER.PD within this package. |
| 5 |
*/ |
| 6 |
/* |
| 7 |
* Written by J.T. Conklin <[email protected]>. |
| 8 |
* Changes for long double by Ulrich Drepper <[email protected]> |
| 9 |
* Public domain. |
| 10 |
*/ |
| 11 |
|
| 12 |
#include <math.h> |
| 13 |
|
| 14 |
double |
| 15 |
logb (double x) |
| 16 |
{ |
| 17 |
#ifdef __x86_64__ |
| 18 |
__mingw_dbl_type_t hlp; |
| 19 |
int lx, hx; |
| 20 |
|
| 21 |
hlp.x = x; |
| 22 |
lx = hlp.lh.low; |
| 23 |
hx = hlp.lh.high & 0x7fffffff; /* high |x| */ |
| 24 |
if ((hx | lx) == 0) |
| 25 |
return -1.0 / fabs (x); |
| 26 |
if (hx >= 0x7ff00000) |
| 27 |
return x * x; |
| 28 |
if ((hx >>= 20) == 0) { |
| 29 |
unsigned long long mantissa = hlp.val & 0xfffffffffffffULL; |
| 30 |
return -1023.0 - (__builtin_clzll(mantissa) - 12); |
| 31 |
} |
| 32 |
return (double) (hx - 1023); |
| 33 |
#else |
| 34 |
double res = 0.0; |
| 35 |
asm volatile ( |
| 36 |
"fxtract\n\t" |
| 37 |
"fstp %%st" : "=t" (res) : "0" (x)); |
| 38 |
return res; |
| 39 |
#endif |
| 40 |
} |