Branch data Line data Source code
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 : : */
12 : :
13 : : #include "cdefs-compat.h"
14 : : //__FBSDID("$FreeBSD: src/lib/msun/src/s_ilogbl.c,v 1.2 2008/02/22 02:30:35 das Exp $");
15 : :
16 : : #include <float.h>
17 : : #include <limits.h>
18 : : #include <openlibm_math.h>
19 : :
20 : : #include "fpmath.h"
21 : : #include "math_private.h"
22 : :
23 : : OLM_DLLEXPORT int
24 : 0 : ilogbl(long double x)
25 : : {
26 : : union IEEEl2bits u;
27 : : unsigned long m;
28 : : int b;
29 : :
30 : 0 : u.e = x;
31 [ # # ]: 0 : if (u.bits.exp == 0) {
32 [ # # ]: 0 : if ((u.bits.manl | u.bits.manh) == 0)
33 : 0 : return (FP_ILOGB0);
34 : : /* denormalized */
35 [ # # ]: 0 : if (u.bits.manh == 0) {
36 : 0 : m = 1lu << (LDBL_MANL_SIZE - 1);
37 [ # # ]: 0 : for (b = LDBL_MANH_SIZE; !(u.bits.manl & m); m >>= 1)
38 : 0 : b++;
39 : : } else {
40 : 0 : m = 1lu << (LDBL_MANH_SIZE - 1);
41 [ # # ]: 0 : for (b = 0; !(u.bits.manh & m); m >>= 1)
42 : 0 : b++;
43 : : }
44 : : #ifdef LDBL_IMPLICIT_NBIT
45 : : b++;
46 : : #endif
47 : 0 : return (LDBL_MIN_EXP - b - 1);
48 [ # # ]: 0 : } else if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1)
49 : 0 : return (u.bits.exp - LDBL_MAX_EXP + 1);
50 [ # # # # ]: 0 : else if (u.bits.manl != 0 || u.bits.manh != 0)
51 : 0 : return (FP_ILOGBNAN);
52 : : else
53 : 0 : return (INT_MAX);
54 : : }
|