Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3362 | Serge | 1 | /* 2009 for Newlib: Sun's sf_ilogb.c converted to be sf_logb.c. */ |
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 | /* float logb(float x) |
||
14 | * return the binary exponent of non-zero x |
||
15 | * logbf(0) = -inf, raise divide-by-zero floating point exception |
||
16 | * logbf(+inf|-inf) = +inf (no signal is raised) |
||
17 | * logbf(NaN) = NaN (no signal is raised) |
||
18 | * Per C99 recommendation, a NaN argument is returned unchanged. |
||
19 | */ |
||
20 | |||
21 | #include "fdlibm.h" |
||
22 | |||
23 | float |
||
24 | #ifdef __STDC__ |
||
25 | logbf(float x) |
||
26 | #else |
||
27 | logbf(x) |
||
28 | float x; |
||
29 | #endif |
||
30 | { |
||
31 | __int32_t hx,ix; |
||
32 | |||
33 | GET_FLOAT_WORD(hx,x); |
||
34 | hx &= 0x7fffffff; |
||
35 | if(FLT_UWORD_IS_ZERO(hx)) { |
||
36 | float xx; |
||
37 | /* arg==0: return -inf and raise divide-by-zero exception */ |
||
38 | SET_FLOAT_WORD(xx,hx); /* +0.0 */ |
||
39 | return -1./xx; /* logbf(0) = -inf */ |
||
40 | } |
||
41 | if(FLT_UWORD_IS_SUBNORMAL(hx)) { |
||
42 | for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1; |
||
43 | return (float) ix; |
||
44 | } |
||
45 | else if (FLT_UWORD_IS_INFINITE(hx)) return HUGE_VALF; /* x==+|-inf */ |
||
46 | else if (FLT_UWORD_IS_NAN(hx)) return x; |
||
47 | else return (float) ((hx>>23)-127); |
||
48 | } |
||
49 | |||
50 | #ifdef _DOUBLE_IS_32BITS |
||
51 | |||
52 | #ifdef __STDC__ |
||
53 | double logb(double x) |
||
54 | #else |
||
55 | double logb(x) |
||
56 | double x; |
||
57 | #endif |
||
58 | { |
||
59 | return (double) logbf((float) x); |
||
60 | } |
||
61 | |||
62 | #endif /* defined(_DOUBLE_IS_32BITS) */=1)><=1)>=8;><=8;> |