LCOV - code coverage report
Current view: top level - src - s_log1pf.c (source / functions) Coverage Total Hit
Test: app.info Lines: 71.4 % 49 35
Test Date: 2024-01-11 15:52:50 Functions: 100.0 % 1 1
Branches: 61.1 % 36 22

             Branch data     Line data    Source code
       1                 :             : /* s_log1pf.c -- float version of s_log1p.c.
       2                 :             :  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
       3                 :             :  */
       4                 :             : 
       5                 :             : /*
       6                 :             :  * ====================================================
       7                 :             :  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
       8                 :             :  *
       9                 :             :  * Developed at SunPro, a Sun Microsystems, Inc. business.
      10                 :             :  * Permission to use, copy, modify, and distribute this
      11                 :             :  * software is freely granted, provided that this notice
      12                 :             :  * is preserved.
      13                 :             :  * ====================================================
      14                 :             :  */
      15                 :             : 
      16                 :             : #include "cdefs-compat.h"
      17                 :             : //__FBSDID("$FreeBSD: src/lib/msun/src/s_log1pf.c,v 1.12 2008/03/29 16:37:59 das Exp $");
      18                 :             : 
      19                 :             : #include <float.h>
      20                 :             : #include <openlibm_math.h>
      21                 :             : 
      22                 :             : #include "math_private.h"
      23                 :             : 
      24                 :             : static const float
      25                 :             : ln2_hi =   6.9313812256e-01,    /* 0x3f317180 */
      26                 :             : ln2_lo =   9.0580006145e-06,    /* 0x3717f7d1 */
      27                 :             : two25 =    3.355443200e+07,     /* 0x4c000000 */
      28                 :             : Lp1 = 6.6666668653e-01, /* 3F2AAAAB */
      29                 :             : Lp2 = 4.0000000596e-01, /* 3ECCCCCD */
      30                 :             : Lp3 = 2.8571429849e-01, /* 3E924925 */
      31                 :             : Lp4 = 2.2222198546e-01, /* 3E638E29 */
      32                 :             : Lp5 = 1.8183572590e-01, /* 3E3A3325 */
      33                 :             : Lp6 = 1.5313838422e-01, /* 3E1CD04F */
      34                 :             : Lp7 = 1.4798198640e-01; /* 3E178897 */
      35                 :             : 
      36                 :             : static const float zero = 0.0;
      37                 :             : 
      38                 :             : OLM_DLLEXPORT float
      39                 :          13 : log1pf(float x)
      40                 :             : {
      41                 :             :         float hfsq,f,c,s,z,R,u;
      42                 :             :         int32_t k,hx,hu,ax;
      43                 :             : 
      44                 :          13 :         GET_FLOAT_WORD(hx,x);
      45                 :          13 :         ax = hx&0x7fffffff;
      46                 :             : 
      47                 :          13 :         k = 1;
      48         [ +  + ]:          13 :         if (hx < 0x3ed413d0) {                       /* 1+x < sqrt(2)+  */
      49         [ +  + ]:           7 :             if(ax>=0x3f800000) {             /* x <= -1.0 */
      50         [ +  + ]:           3 :                 if(x==(float)-1.0) return -two25/zero; /* log1p(-1)=+inf */
      51                 :           2 :                 else return (x-x)/(x-x);        /* log1p(x<-1)=NaN */
      52                 :             :             }
      53         [ +  + ]:           4 :             if(ax<0x38000000) {                      /* |x| < 2**-15 */
      54         [ +  - ]:           3 :                 if(two25+x>zero                      /* raise inexact */
      55         [ +  - ]:           3 :                     &&ax<0x33800000)                 /* |x| < 2**-24 */
      56                 :           3 :                     return x;
      57                 :             :                 else
      58                 :           0 :                     return x - x*x*(float)0.5;
      59                 :             :             }
      60   [ +  -  -  + ]:           1 :             if(hx>0||hx<=((int32_t)0xbe95f619)) {
      61                 :           0 :                 k=0;f=x;hu=1;}          /* sqrt(2)/2- <= 1+x < sqrt(2)+ */
      62                 :             :         }
      63         [ +  + ]:           7 :         if (hx >= 0x7f800000) return x+x;
      64         [ +  - ]:           6 :         if(k!=0) {
      65         [ +  - ]:           6 :             if(hx<0x5a000000) {
      66                 :           6 :                 STRICT_ASSIGN(float,u,(float)1.0+x);
      67                 :           6 :                 GET_FLOAT_WORD(hu,u);
      68                 :           6 :                 k  = (hu>>23)-127;
      69                 :             :                 /* correction term */
      70         [ +  + ]:           6 :                 c  = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0);
      71                 :           6 :                 c /= u;
      72                 :             :             } else {
      73                 :           0 :                 u  = x;
      74                 :           0 :                 GET_FLOAT_WORD(hu,u);
      75                 :           0 :                 k  = (hu>>23)-127;
      76                 :           0 :                 c  = 0;
      77                 :             :             }
      78                 :           6 :             hu &= 0x007fffff;
      79                 :             :             /*
      80                 :             :              * The approximation to sqrt(2) used in thresholds is not
      81                 :             :              * critical.  However, the ones used above must give less
      82                 :             :              * strict bounds than the one here so that the k==0 case is
      83                 :             :              * never reached from here, since here we have committed to
      84                 :             :              * using the correction term but don't use it if k==0.
      85                 :             :              */
      86         [ +  + ]:           6 :             if(hu<0x3504f4) {                        /* u < sqrt(2) */
      87                 :           2 :                 SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */
      88                 :             :             } else {
      89                 :           4 :                 k += 1;
      90                 :           4 :                 SET_FLOAT_WORD(u,hu|0x3f000000);        /* normalize u/2 */
      91                 :           4 :                 hu = (0x00800000-hu)>>2;
      92                 :             :             }
      93                 :           6 :             f = u-(float)1.0;
      94                 :             :         }
      95                 :           6 :         hfsq=(float)0.5*f*f;
      96         [ -  + ]:           6 :         if(hu==0) {     /* |f| < 2**-20 */
      97         [ #  # ]:           0 :             if(f==zero) {
      98         [ #  # ]:           0 :                 if(k==0) {
      99                 :           0 :                     return zero;
     100                 :             :                 } else {
     101                 :           0 :                     c += k*ln2_lo;
     102                 :           0 :                     return k*ln2_hi+c;
     103                 :             :                 }
     104                 :             :             }
     105                 :           0 :             R = hfsq*((float)1.0-(float)0.66666666666666666*f);
     106         [ #  # ]:           0 :             if(k==0) return f-R; else
     107                 :           0 :                      return k*ln2_hi-((R-(k*ln2_lo+c))-f);
     108                 :             :         }
     109                 :           6 :         s = f/((float)2.0+f);
     110                 :           6 :         z = s*s;
     111                 :           6 :         R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
     112         [ -  + ]:           6 :         if(k==0) return f-(hfsq-s*(hfsq+R)); else
     113                 :           6 :                  return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
     114                 :             : }
        

Generated by: LCOV version 2.0-115.g950771e