s_log1pf.c revision 2116
12116Sjkh/* s_log1pf.c -- float version of s_log1p.c. 22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 32116Sjkh */ 42116Sjkh 52116Sjkh/* 62116Sjkh * ==================================================== 72116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 82116Sjkh * 92116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 102116Sjkh * Permission to use, copy, modify, and distribute this 112116Sjkh * software is freely granted, provided that this notice 122116Sjkh * is preserved. 132116Sjkh * ==================================================== 142116Sjkh */ 152116Sjkh 162116Sjkh#ifndef lint 172116Sjkhstatic char rcsid[] = "$Id: s_log1pf.c,v 1.2 1994/08/18 23:07:02 jtc Exp $"; 182116Sjkh#endif 192116Sjkh 202116Sjkh#include "math.h" 212116Sjkh#include "math_private.h" 222116Sjkh 232116Sjkh#ifdef __STDC__ 242116Sjkhstatic const float 252116Sjkh#else 262116Sjkhstatic float 272116Sjkh#endif 282116Sjkhln2_hi = 6.9313812256e-01, /* 0x3f317180 */ 292116Sjkhln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ 302116Sjkhtwo25 = 3.355443200e+07, /* 0x4c000000 */ 312116SjkhLp1 = 6.6666668653e-01, /* 3F2AAAAB */ 322116SjkhLp2 = 4.0000000596e-01, /* 3ECCCCCD */ 332116SjkhLp3 = 2.8571429849e-01, /* 3E924925 */ 342116SjkhLp4 = 2.2222198546e-01, /* 3E638E29 */ 352116SjkhLp5 = 1.8183572590e-01, /* 3E3A3325 */ 362116SjkhLp6 = 1.5313838422e-01, /* 3E1CD04F */ 372116SjkhLp7 = 1.4798198640e-01; /* 3E178897 */ 382116Sjkh 392116Sjkh#ifdef __STDC__ 402116Sjkhstatic const float zero = 0.0; 412116Sjkh#else 422116Sjkhstatic float zero = 0.0; 432116Sjkh#endif 442116Sjkh 452116Sjkh#ifdef __STDC__ 462116Sjkh float log1pf(float x) 472116Sjkh#else 482116Sjkh float log1pf(x) 492116Sjkh float x; 502116Sjkh#endif 512116Sjkh{ 522116Sjkh float hfsq,f,c,s,z,R,u; 532116Sjkh int32_t k,hx,hu,ax; 542116Sjkh 552116Sjkh GET_FLOAT_WORD(hx,x); 562116Sjkh ax = hx&0x7fffffff; 572116Sjkh 582116Sjkh k = 1; 592116Sjkh if (hx < 0x3ed413d7) { /* x < 0.41422 */ 602116Sjkh if(ax>=0x3f800000) { /* x <= -1.0 */ 612116Sjkh if(x==(float)-1.0) return -two25/zero; /* log1p(-1)=+inf */ 622116Sjkh else return (x-x)/(x-x); /* log1p(x<-1)=NaN */ 632116Sjkh } 642116Sjkh if(ax<0x31000000) { /* |x| < 2**-29 */ 652116Sjkh if(two25+x>zero /* raise inexact */ 662116Sjkh &&ax<0x24800000) /* |x| < 2**-54 */ 672116Sjkh return x; 682116Sjkh else 692116Sjkh return x - x*x*(float)0.5; 702116Sjkh } 712116Sjkh if(hx>0||hx<=((int32_t)0xbe95f61f)) { 722116Sjkh k=0;f=x;hu=1;} /* -0.2929<x<0.41422 */ 732116Sjkh } 742116Sjkh if (hx >= 0x7f800000) return x+x; 752116Sjkh if(k!=0) { 762116Sjkh if(hx<0x5a000000) { 772116Sjkh u = (float)1.0+x; 782116Sjkh GET_FLOAT_WORD(hu,u); 792116Sjkh k = (hu>>23)-127; 802116Sjkh /* correction term */ 812116Sjkh c = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0); 822116Sjkh c /= u; 832116Sjkh } else { 842116Sjkh u = x; 852116Sjkh GET_FLOAT_WORD(hu,u); 862116Sjkh k = (hu>>23)-127; 872116Sjkh c = 0; 882116Sjkh } 892116Sjkh hu &= 0x007fffff; 902116Sjkh if(hu<0x3504f7) { 912116Sjkh SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */ 922116Sjkh } else { 932116Sjkh k += 1; 942116Sjkh SET_FLOAT_WORD(u,hu|0x3f000000); /* normalize u/2 */ 952116Sjkh hu = (0x00800000-hu)>>2; 962116Sjkh } 972116Sjkh f = u-(float)1.0; 982116Sjkh } 992116Sjkh hfsq=(float)0.5*f*f; 1002116Sjkh if(hu==0) { /* |f| < 2**-20 */ 1012116Sjkh if(f==zero) if(k==0) return zero; 1022116Sjkh else {c += k*ln2_lo; return k*ln2_hi+c;} 1032116Sjkh R = hfsq*((float)1.0-(float)0.66666666666666666*f); 1042116Sjkh if(k==0) return f-R; else 1052116Sjkh return k*ln2_hi-((R-(k*ln2_lo+c))-f); 1062116Sjkh } 1072116Sjkh s = f/((float)2.0+f); 1082116Sjkh z = s*s; 1092116Sjkh R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7)))))); 1102116Sjkh if(k==0) return f-(hfsq-s*(hfsq+R)); else 1112116Sjkh return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f); 1122116Sjkh} 113