|
Packit Service |
82fcde |
/* s_log1pf.c -- float version of s_log1p.c.
|
|
Packit Service |
82fcde |
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/*
|
|
Packit Service |
82fcde |
* ====================================================
|
|
Packit Service |
82fcde |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit Service |
82fcde |
*
|
|
Packit Service |
82fcde |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit Service |
82fcde |
* Permission to use, copy, modify, and distribute this
|
|
Packit Service |
82fcde |
* software is freely granted, provided that this notice
|
|
Packit Service |
82fcde |
* is preserved.
|
|
Packit Service |
82fcde |
* ====================================================
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <float.h>
|
|
Packit Service |
82fcde |
#include <math.h>
|
|
Packit Service |
82fcde |
#include <math-barriers.h>
|
|
Packit Service |
82fcde |
#include <math_private.h>
|
|
Packit Service |
82fcde |
#include <math-underflow.h>
|
|
Packit Service |
82fcde |
#include <libc-diag.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static const float
|
|
Packit Service |
82fcde |
ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
|
|
Packit Service |
82fcde |
ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
|
|
Packit Service |
82fcde |
two25 = 3.355443200e+07, /* 0x4c000000 */
|
|
Packit Service |
82fcde |
Lp1 = 6.6666668653e-01, /* 3F2AAAAB */
|
|
Packit Service |
82fcde |
Lp2 = 4.0000000596e-01, /* 3ECCCCCD */
|
|
Packit Service |
82fcde |
Lp3 = 2.8571429849e-01, /* 3E924925 */
|
|
Packit Service |
82fcde |
Lp4 = 2.2222198546e-01, /* 3E638E29 */
|
|
Packit Service |
82fcde |
Lp5 = 1.8183572590e-01, /* 3E3A3325 */
|
|
Packit Service |
82fcde |
Lp6 = 1.5313838422e-01, /* 3E1CD04F */
|
|
Packit Service |
82fcde |
Lp7 = 1.4798198640e-01; /* 3E178897 */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static const float zero = 0.0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
float
|
|
Packit Service |
82fcde |
__log1pf(float x)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
float hfsq,f,c,s,z,R,u;
|
|
Packit Service |
82fcde |
int32_t k,hx,hu,ax;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
GET_FLOAT_WORD(hx,x);
|
|
Packit Service |
82fcde |
ax = hx&0x7fffffff;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
k = 1;
|
|
Packit Service |
82fcde |
if (hx < 0x3ed413d7) { /* x < 0.41422 */
|
|
Packit Service |
82fcde |
if(ax>=0x3f800000) { /* x <= -1.0 */
|
|
Packit Service |
82fcde |
if(x==(float)-1.0) return -two25/zero; /* log1p(-1)=-inf */
|
|
Packit Service |
82fcde |
else return (x-x)/(x-x); /* log1p(x<-1)=NaN */
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if(ax<0x31000000) { /* |x| < 2**-29 */
|
|
Packit Service |
82fcde |
math_force_eval(two25+x); /* raise inexact */
|
|
Packit Service |
82fcde |
if (ax<0x24800000) /* |x| < 2**-54 */
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
math_check_force_underflow (x);
|
|
Packit Service |
82fcde |
return x;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
return x - x*x*(float)0.5;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if(hx>0||hx<=((int32_t)0xbe95f61f)) {
|
|
Packit Service |
82fcde |
k=0;f=x;hu=1;} /* -0.2929
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (hx >= 0x7f800000) return x+x;
|
|
Packit Service |
82fcde |
if(k!=0) {
|
|
Packit Service |
82fcde |
if(hx<0x5a000000) {
|
|
Packit Service |
82fcde |
u = (float)1.0+x;
|
|
Packit Service |
82fcde |
GET_FLOAT_WORD(hu,u);
|
|
Packit Service |
82fcde |
k = (hu>>23)-127;
|
|
Packit Service |
82fcde |
/* correction term */
|
|
Packit Service |
82fcde |
c = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0);
|
|
Packit Service |
82fcde |
c /= u;
|
|
Packit Service |
82fcde |
} else {
|
|
Packit Service |
82fcde |
u = x;
|
|
Packit Service |
82fcde |
GET_FLOAT_WORD(hu,u);
|
|
Packit Service |
82fcde |
k = (hu>>23)-127;
|
|
Packit Service |
82fcde |
c = 0;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
hu &= 0x007fffff;
|
|
Packit Service |
82fcde |
if(hu<0x3504f7) {
|
|
Packit Service |
82fcde |
SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */
|
|
Packit Service |
82fcde |
} else {
|
|
Packit Service |
82fcde |
k += 1;
|
|
Packit Service |
82fcde |
SET_FLOAT_WORD(u,hu|0x3f000000); /* normalize u/2 */
|
|
Packit Service |
82fcde |
hu = (0x00800000-hu)>>2;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
f = u-(float)1.0;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
hfsq=(float)0.5*f*f;
|
|
Packit Service |
82fcde |
if(hu==0) { /* |f| < 2**-20 */
|
|
Packit Service |
82fcde |
if(f==zero) {
|
|
Packit Service |
82fcde |
if(k==0) return zero;
|
|
Packit Service |
82fcde |
else {c += k*ln2_lo; return k*ln2_hi+c;}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
R = hfsq*((float)1.0-(float)0.66666666666666666*f);
|
|
Packit Service |
82fcde |
if(k==0) return f-R; else
|
|
Packit Service |
82fcde |
return k*ln2_hi-((R-(k*ln2_lo+c))-f);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
s = f/((float)2.0+f);
|
|
Packit Service |
82fcde |
z = s*s;
|
|
Packit Service |
82fcde |
R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
|
|
Packit Service |
82fcde |
if (k == 0)
|
|
Packit Service |
82fcde |
return f - (hfsq - s * (hfsq + R));
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* With GCC 7 when compiling with -Os the compiler warns
|
|
Packit Service |
82fcde |
that c might be used uninitialized. This can't be true
|
|
Packit Service |
82fcde |
because k must be 0 for c to be uninitialized and we
|
|
Packit Service |
82fcde |
handled that computation earlier without using c. */
|
|
Packit Service |
82fcde |
DIAG_PUSH_NEEDS_COMMENT;
|
|
Packit Service |
82fcde |
DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
|
|
Packit Service |
82fcde |
return k * ln2_hi - ((hfsq - (s * (hfsq + R)
|
|
Packit Service |
82fcde |
+ (k * ln2_lo + c))) - f);
|
|
Packit Service |
82fcde |
DIAG_POP_NEEDS_COMMENT;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|