ipiq: Add simple IPI latency measure sysctls (2)
[dragonfly.git] / lib / libm / src / s_logbl.c
1 /*
2  * From: @(#)s_ilogb.c 5.1 93/09/24
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  * $FreeBSD: head/lib/msun/src/s_logbl.c 174698 2007-12-17 03:53:38Z das $
12  */
13
14
15 #include <float.h>
16 #include <limits.h>
17 #include <math.h>
18
19 #include "fpmath.h"
20
21 long double
22 logbl(long double x)
23 {
24         union IEEEl2bits u;
25         unsigned long m;
26         int b;
27
28         u.e = x;
29         if (u.bits.exp == 0) {
30                 if ((u.bits.manl | u.bits.manh) == 0) { /* x == 0 */
31                         u.bits.sign = 1;
32                         return (1.0L / u.e);
33                 }
34                 /* denormalized */
35                 if (u.bits.manh == 0) {
36                         m = 1lu << (LDBL_MANL_SIZE - 1);
37                         for (b = LDBL_MANH_SIZE; !(u.bits.manl & m); m >>= 1)
38                                 b++;
39                 } else {
40                         m = 1lu << (LDBL_MANH_SIZE - 1);
41                         for (b = 0; !(u.bits.manh & m); m >>= 1)
42                                 b++;
43                 }
44 #ifdef LDBL_IMPLICIT_NBIT
45                 b++;
46 #endif
47                 return ((long double)(LDBL_MIN_EXP - b - 1));
48         }
49         if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1)       /* normal */
50                 return ((long double)(u.bits.exp - LDBL_MAX_EXP + 1));
51         else                                            /* +/- inf or nan */
52                 return (x * x);
53 }