Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | |
2 | /* |
||
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 | |||
14 | FUNCTION |
||
15 | < |
||
16 | INDEX |
||
17 | ilogb |
||
18 | INDEX |
||
19 | ilogbf |
||
20 | |||
21 | |||
22 | #include |
||
23 | int ilogb(double <[val]>); |
||
24 | int ilogbf(float <[val]>); |
||
25 | |||
26 | |||
27 | #include |
||
28 | int ilogb(<[val]>) |
||
29 | double <[val]>; |
||
30 | |||
31 | |||
32 | float <[val]>; |
||
33 | |||
34 | |||
35 | |||
36 | |||
37 | |||
38 | 2**<[p]>. < |
||
39 | <[val]>, and return <[p]>. The functions < |
||
40 | < |
||
41 | return <[m]>. |
||
42 | |||
43 | |||
44 | |||
45 | |||
46 | floating-point argument. |
||
47 | If <[val]> is <<0>>, they return < |
||
48 | If <[val]> is infinite, they return < |
||
49 | If <[val]> is NaN, they return < |
||
50 | (< |
||
51 | defined as INT_MIN or INT_MAX from limits.h. The value of FP_ILOGB0 may be |
||
52 | either INT_MIN or -INT_MAX. The value of FP_ILOGBNAN may be either INT_MAX or |
||
53 | INT_MIN.) |
||
54 | |||
55 | |||
56 | @comment behavior of much of the Newlib math library. |
||
57 | @comment BUGS |
||
58 | @comment On errors, errno is not set per C99 and POSIX requirements even if |
||
59 | @comment (math_errhandling & MATH_ERRNO) is non-zero. |
||
60 | |||
61 | |||
62 | C99, POSIX |
||
63 | */ |
||
64 | |||
65 | |||
66 | * return the binary exponent of non-zero x |
||
67 | * ilogb(0) = 0x80000001 |
||
68 | * ilogb(inf/NaN) = 0x7fffffff (no signal is raised) |
||
69 | */ |
||
70 | |||
71 | |||
72 | #include "fdlibm.h" |
||
73 | |||
74 | |||
75 | |||
76 | |||
77 | int ilogb(double x) |
||
78 | #else |
||
79 | int ilogb(x) |
||
80 | double x; |
||
81 | #endif |
||
82 | { |
||
83 | __int32_t hx,lx,ix; |
||
84 | |||
85 | |||
86 | hx &= 0x7fffffff; |
||
87 | if(hx<0x00100000) { |
||
88 | if((hx|lx)==0) |
||
89 | return FP_ILOGB0; /* ilogb(0) = special case error */ |
||
90 | else /* subnormal x */ |
||
91 | if(hx==0) { |
||
92 | for (ix = -1043; lx>0; lx<<=1) ix -=1; |
||
93 | } else { |
||
94 | for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1; |
||
95 | } |
||
96 | return ix; |
||
97 | } |
||
98 | else if (hx<0x7ff00000) return (hx>>20)-1023; |
||
99 | #if FP_ILOGBNAN != INT_MAX |
||
100 | else if (hx>0x7ff00000) return FP_ILOGBNAN; /* NAN */ |
||
101 | #endif |
||
102 | else return INT_MAX; /* infinite (or, possibly, NAN) */ |
||
103 | } |
||
104 | |||
105 | |||
106 |