POK
e_log10f.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Fri Jan 30 14:41:34 2009
15  */
16 
17 /* e_log10f.c -- float version of e_log10.c.
18  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
19  */
20 
21 /*
22  * ====================================================
23  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
24  *
25  * Developed at SunPro, a Sun Microsystems, Inc. business.
26  * Permission to use, copy, modify, and distribute this
27  * software is freely granted, provided that this notice
28  * is preserved.
29  * ====================================================
30  */
31 
32 #ifdef POK_NEEDS_LIBMATH
33 
34 #include "math_private.h"
35 
36 static const float
37 two25 = 3.3554432000e+07, /* 0x4c000000 */
38 ivln10 = 4.3429449201e-01, /* 0x3ede5bd9 */
39 log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */
40 log10_2lo = 7.9034151668e-07; /* 0x355427db */
41 
42 static const float zero = 0.0;
43 
44 float
45 __ieee754_log10f(float x)
46 {
47  float y,z;
48  int32_t i,k,hx;
49 
50  GET_FLOAT_WORD(hx,x);
51 
52  k=0;
53  if (hx < 0x00800000) { /* x < 2**-126 */
54  if ((hx&0x7fffffff)==0)
55  return -two25/zero; /* log(+-0)=-inf */
56  if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
57  k -= 25; x *= two25; /* subnormal number, scale up x */
58  GET_FLOAT_WORD(hx,x);
59  }
60  if (hx >= 0x7f800000) return x+x;
61  k += (hx>>23)-127;
62  i = ((uint32_t)k&0x80000000)>>31;
63  hx = (hx&0x007fffff)|((0x7f-i)<<23);
64  y = (float)(k+i);
65  SET_FLOAT_WORD(x,hx);
66  z = y*log10_2lo + ivln10*__ieee754_logf(x);
67  return z+y*log10_2hi;
68 }
69 
70 #endif