Print this page
11210 libm should be cstyle(1ONBLD) clean

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/complex/casinl.c
          +++ new/usr/src/lib/libm/common/complex/casinl.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24   24   */
       25 +
  25   26  /*
  26   27   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27   28   * Use is subject to license terms.
  28   29   */
  29   30  
  30   31  #pragma weak __casinl = casinl
  31   32  
  32      -#include "libm.h"               /* asinl/atanl/fabsl/isinfl/log1pl/logl/sqrtl */
       33 +#include "libm.h"       /* asinl/atanl/fabsl/isinfl/log1pl/logl/sqrtl */
  33   34  #include "complex_wrapper.h"
  34   35  #include "longdouble.h"
  35   36  
  36      -/* INDENT OFF */
  37      -static const long double
  38      -zero = 0.0L,
  39      -one = 1.0L,
  40      -Acrossover = 1.5L,
  41      -Bcrossover = 0.6417L,
  42      -half = 0.5L,
  43      -ln2 = 6.931471805599453094172321214581765680755e-0001L,
  44      -Foursqrtu = 7.3344154702193886624856495681939326638255e-2466L,  /* 2**-8189 */
       37 +/* BEGIN CSTYLED */
       38 +static const long double zero = 0.0L,
       39 +        one = 1.0L,
       40 +        Acrossover = 1.5L,
       41 +        Bcrossover = 0.6417L,
       42 +        half = 0.5L,
       43 +        ln2 = 6.931471805599453094172321214581765680755e-0001L,
       44 +        Foursqrtu = 7.3344154702193886624856495681939326638255e-2466L,  /* 2**-8189 */
  45   45  #if defined(__x86)
  46      -E = 5.4210108624275221700372640043497085571289e-20L,    /* 2**-64 */
  47      -pi_4 = 0.7853981633974483095739921312272713294078130L,
  48      -pi_4_l = 4.1668714592604391641479322342670193036704898e-20L,
  49      -pi_2 = 1.5707963267948966191479842624545426588156260L,
  50      -pi_2_l = 8.3337429185208783282958644685340386073409796e-20L;
  51      -
       46 +        E = 5.4210108624275221700372640043497085571289e-20L,    /* 2**-64 */
       47 +        pi_4 = 0.7853981633974483095739921312272713294078130L,
       48 +        pi_4_l = 4.1668714592604391641479322342670193036704898e-20L,
       49 +        pi_2 = 1.5707963267948966191479842624545426588156260L,
       50 +        pi_2_l = 8.3337429185208783282958644685340386073409796e-20L;
  52   51  #else
  53      -E = 9.6296497219361792652798897129246365926905e-35L,    /* 2**-113 */
  54      -pi_4 = 0.7853981633974483096156608458198756993697670L,
  55      -pi_4_l = 2.1679525325309452561992610065108379921905808e-35L,
  56      -pi_2 = 1.5707963267948966192313216916397513987395340L,
  57      -pi_2_l = 4.3359050650618905123985220130216759843811616e-35L;
  58      -
       52 +        E = 9.6296497219361792652798897129246365926905e-35L,    /* 2**-113 */
       53 +        pi_4 = 0.7853981633974483096156608458198756993697670L,
       54 +        pi_4_l = 2.1679525325309452561992610065108379921905808e-35L,
       55 +        pi_2 = 1.5707963267948966192313216916397513987395340L,
       56 +        pi_2_l = 4.3359050650618905123985220130216759843811616e-35L;
  59   57  #endif
  60      -/* INDENT ON */
       58 +/* END CSTYLED */
  61   59  
  62   60  #if defined(__x86)
  63   61  static const int ip1 = 0x40400000;      /* 2**65 */
  64   62  #else
  65   63  static const int ip1 = 0x40710000;      /* 2**114 */
  66   64  #endif
  67   65  
  68   66  ldcomplex
  69      -casinl(ldcomplex z) {
       67 +casinl(ldcomplex z)
       68 +{
  70   69          long double x, y, t, R, S, A, Am1, B, y2, xm1, xp1, Apx;
  71   70          int ix, iy, hx, hy;
  72   71          ldcomplex ans;
  73   72  
  74   73          x = LD_RE(z);
  75   74          y = LD_IM(z);
  76   75          hx = HI_XWORD(x);
  77   76          hy = HI_XWORD(y);
  78   77          ix = hx & 0x7fffffff;
  79   78          iy = hy & 0x7fffffff;
  80   79          x = fabsl(x);
  81   80          y = fabsl(y);
  82   81  
  83   82          /* special cases */
  84   83  
  85   84          /* x is inf or NaN */
  86      -        if (ix >= 0x7fff0000) { /* x is inf or NaN */
       85 +        if (ix >= 0x7fff0000) {         /* x is inf or NaN */
  87   86                  if (isinfl(x)) {        /* x is INF */
  88   87                          LD_IM(ans) = x;
       88 +
  89   89                          if (iy >= 0x7fff0000) {
  90   90                                  if (isinfl(y))
  91   91                                          /* casin(inf + i inf) = pi/4 + i inf */
  92   92                                          LD_RE(ans) = pi_4 + pi_4_l;
  93   93                                  else    /* casin(inf + i NaN) = NaN + i inf */
  94   94                                          LD_RE(ans) = y + y;
  95      -                        } else  /* casin(inf + iy) = pi/2 + i inf */
       95 +                        } else { /* casin(inf + iy) = pi/2 + i inf */
  96   96                                  LD_RE(ans) = pi_2 + pi_2_l;
       97 +                        }
  97   98                  } else {                /* x is NaN */
  98   99                          if (iy >= 0x7fff0000) {
  99      -                                /* INDENT OFF */
      100 +
 100  101                                  /*
 101  102                                   * casin(NaN + i inf) = NaN  + i inf
 102  103                                   * casin(NaN + i NaN) = NaN  + i NaN
 103  104                                   */
 104      -                                /* INDENT ON */
 105  105                                  LD_IM(ans) = y + y;
 106  106                                  LD_RE(ans) = x + x;
 107  107                          } else {
 108      -                                /* INDENT OFF */
 109      -                                /* casin(NaN + i y ) = NaN  + i NaN */
 110      -                                /* INDENT ON */
      108 +                                /*
      109 +                                 * casin(NaN + i y ) = NaN  + i NaN
      110 +                                 */
 111  111                                  LD_IM(ans) = LD_RE(ans) = x + y;
 112  112                          }
 113  113                  }
      114 +
 114  115                  if (hx < 0)
 115  116                          LD_RE(ans) = -LD_RE(ans);
      117 +
 116  118                  if (hy < 0)
 117  119                          LD_IM(ans) = -LD_IM(ans);
      120 +
 118  121                  return (ans);
 119  122          }
 120  123  
 121  124          /* casin(+0 + i 0) = 0 + i 0. */
 122  125          if (x == zero && y == zero)
 123  126                  return (z);
 124  127  
 125      -        if (iy >= 0x7fff0000) { /* y is inf or NaN */
      128 +        if (iy >= 0x7fff0000) {         /* y is inf or NaN */
 126  129                  if (isinfl(y)) {        /* casin(x + i inf) = 0 + i inf */
 127  130                          LD_IM(ans) = y;
 128  131                          LD_RE(ans) = zero;
 129  132                  } else {                /* casin(x + i NaN) = NaN + i NaN */
 130  133                          LD_IM(ans) = x + y;
      134 +
 131  135                          if (x == zero)
 132  136                                  LD_RE(ans) = x;
 133  137                          else
 134  138                                  LD_RE(ans) = y;
 135  139                  }
      140 +
 136  141                  if (hx < 0)
 137  142                          LD_RE(ans) = -LD_RE(ans);
      143 +
 138  144                  if (hy < 0)
 139  145                          LD_IM(ans) = -LD_IM(ans);
      146 +
 140  147                  return (ans);
 141  148          }
 142  149  
 143      -        if (y == zero) {        /* region 1: y=0 */
      150 +        if (y == zero) {                /* region 1: y=0 */
 144  151                  if (ix < 0x3fff0000) {  /* |x| < 1 */
 145  152                          LD_RE(ans) = asinl(x);
 146  153                          LD_IM(ans) = zero;
 147  154                  } else {
 148  155                          LD_RE(ans) = pi_2 + pi_2_l;
 149      -                        if (ix >= ip1)  /* |x| >= i386 ? 2**65 : 2**114 */
      156 +
      157 +                        if (ix >= ip1) { /* |x| >= i386 ? 2**65 : 2**114 */
 150  158                                  LD_IM(ans) = ln2 + logl(x);
 151      -                        else if (ix >= 0x3fff8000)      /* x > Acrossover */
      159 +                        } else if (ix >= 0x3fff8000) {  /* x > Acrossover */
 152  160                                  LD_IM(ans) = logl(x + sqrtl((x - one) * (x +
 153      -                                        one)));
 154      -                        else {
      161 +                                    one)));
      162 +                        } else {
 155  163                                  xm1 = x - one;
 156  164                                  LD_IM(ans) = log1pl(xm1 + sqrtl(xm1 * (x +
 157      -                                        one)));
      165 +                                    one)));
 158  166                          }
 159  167                  }
 160  168          } else if (y <= E * fabsl(x - one)) {   /* region 2: y < tiny*|x-1| */
 161      -                if (ix < 0x3fff0000) {  /* x < 1 */
      169 +                if (ix < 0x3fff0000) {          /* x < 1 */
 162  170                          LD_RE(ans) = asinl(x);
 163  171                          LD_IM(ans) = y / sqrtl((one + x) * (one - x));
 164  172                  } else {
 165  173                          LD_RE(ans) = pi_2 + pi_2_l;
 166      -                        if (ix >= ip1)  /* i386 ? 2**65 : 2**114 */
      174 +
      175 +                        if (ix >= ip1) /* i386 ? 2**65 : 2**114 */
 167  176                                  LD_IM(ans) = ln2 + logl(x);
 168  177                          else if (ix >= 0x3fff8000)      /* x > Acrossover */
 169  178                                  LD_IM(ans) = logl(x + sqrtl((x - one) * (x +
 170      -                                        one)));
      179 +                                    one)));
 171  180                          else
 172  181                                  LD_IM(ans) = log1pl((x - one) + sqrtl((x -
 173      -                                        one) * (x + one)));
      182 +                                    one) * (x + one)));
 174  183                  }
 175  184          } else if (y < Foursqrtu) {     /* region 3 */
 176  185                  t = sqrtl(y);
 177  186                  LD_RE(ans) = pi_2 - (t - pi_2_l);
 178  187                  LD_IM(ans) = t;
 179  188          } else if (E * y - one >= x) {  /* region 4 */
 180  189                  LD_RE(ans) = x / y;     /* need to fix underflow cases */
 181  190                  LD_IM(ans) = ln2 + logl(y);
 182  191          } else if (ix >= 0x5ffb0000 || iy >= 0x5ffb0000) {
 183  192                  /* region 5: x+1 and y are both (>= sqrt(max)/8) i.e. 2**8188 */
 184  193                  t = x / y;
 185  194                  LD_RE(ans) = atanl(t);
 186  195                  LD_IM(ans) = ln2 + logl(y) + half * log1pl(t * t);
 187  196          } else if (x < Foursqrtu) {
 188  197                  /* region 6: x is very small, < 4sqrt(min) */
 189  198                  A = sqrtl(one + y * y);
 190  199                  LD_RE(ans) = x / A;     /* may underflow */
      200 +
 191  201                  if (iy >= 0x3fff8000)   /* if y > Acrossover */
 192  202                          LD_IM(ans) = logl(y + A);
 193  203                  else
 194  204                          LD_IM(ans) = half * log1pl((y + y) * (y + A));
 195      -        } else {        /* safe region */
      205 +        } else {                        /* safe region */
 196  206                  y2 = y * y;
 197  207                  xp1 = x + one;
 198  208                  xm1 = x - one;
 199  209                  R = sqrtl(xp1 * xp1 + y2);
 200  210                  S = sqrtl(xm1 * xm1 + y2);
 201  211                  A = half * (R + S);
 202  212                  B = x / A;
 203      -                if (B <= Bcrossover)
      213 +
      214 +                if (B <= Bcrossover) {
 204  215                          LD_RE(ans) = asinl(B);
 205      -                else {          /* use atan and an accurate approx to a-x */
      216 +                } else {        /* use atan and an accurate approx to a-x */
 206  217                          Apx = A + x;
      218 +
 207  219                          if (x <= one)
 208  220                                  LD_RE(ans) = atanl(x / sqrtl(half * Apx * (y2 /
 209      -                                        (R + xp1) + (S - xm1))));
      221 +                                    (R + xp1) + (S - xm1))));
 210  222                          else
 211  223                                  LD_RE(ans) = atanl(x / (y * sqrtl(half * (Apx /
 212      -                                        (R + xp1) + Apx / (S + xm1)))));
      224 +                                    (R + xp1) + Apx / (S + xm1)))));
 213  225                  }
      226 +
 214  227                  if (A <= Acrossover) {
 215  228                          /* use log1p and an accurate approx to A-1 */
 216  229                          if (x < one)
 217  230                                  Am1 = half * (y2 / (R + xp1) + y2 / (S - xm1));
 218  231                          else
 219  232                                  Am1 = half * (y2 / (R + xp1) + (S + xm1));
      233 +
 220  234                          LD_IM(ans) = log1pl(Am1 + sqrtl(Am1 * (A + one)));
 221  235                  } else {
 222  236                          LD_IM(ans) = logl(A + sqrtl(A * A - one));
 223  237                  }
 224  238          }
 225  239  
 226  240          if (hx < 0)
 227  241                  LD_RE(ans) = -LD_RE(ans);
      242 +
 228  243          if (hy < 0)
 229  244                  LD_IM(ans) = -LD_IM(ans);
 230  245  
 231  246          return (ans);
 232  247  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX