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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/complex/cacosl.c
          +++ new/usr/src/lib/libm/common/complex/cacosl.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 __cacosl = cacosl
  31   32  
  32      -#include "libm.h"               /* acosl/atanl/fabsl/isinfl/log1pl/logl/sqrtl */
       33 +#include "libm.h"       /* acosl/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 = 3.141592653589793238295968524909085317631252110004425048828125L,
  48      -pi_l = 1.666748583704175665659172893706807721468195923078e-19L,
  49      -pi_2 = 1.5707963267948966191479842624545426588156260L,
  50      -pi_2_l = 8.3337429185208783282958644685340386073409796e-20L,
  51      -pi_4 = 0.78539816339744830957399213122727132940781302750110626220703125L,
  52      -pi_4_l = 4.166871459260439164147932234267019303670489807695410e-20L,
  53      -pi3_4 = 2.35619449019234492872197639368181398822343908250331878662109375L,
  54      -pi3_4_l = 1.250061437778131749244379670280105791101146942308e-19L;
       46 +        E = 5.4210108624275221700372640043497085571289e-20L,    /* 2**-64 */
       47 +        pi = 3.141592653589793238295968524909085317631252110004425048828125L,
       48 +        pi_l = 1.666748583704175665659172893706807721468195923078e-19L,
       49 +        pi_2 = 1.5707963267948966191479842624545426588156260L,
       50 +        pi_2_l = 8.3337429185208783282958644685340386073409796e-20L,
       51 +        pi_4 = 0.78539816339744830957399213122727132940781302750110626220703125L,
       52 +        pi_4_l = 4.166871459260439164147932234267019303670489807695410e-20L,
       53 +        pi3_4 = 2.35619449019234492872197639368181398822343908250331878662109375L,
       54 +        pi3_4_l = 1.250061437778131749244379670280105791101146942308e-19L;
  55   55  #else
  56      -E = 9.6296497219361792652798897129246365926905e-35L,            /* 2**-113 */
  57      -pi = 3.1415926535897932384626433832795027974790680981372955730045043318L,
  58      -pi_l = 8.6718101301237810247970440260433519687623233462565303417759356862e-35L,
  59      -pi_2 = 1.5707963267948966192313216916397513987395340L,
  60      -pi_2_l = 4.3359050650618905123985220130216759843811616e-35L,
  61      -pi_4 = 0.785398163397448309615660845819875699369767024534323893251126L,
  62      -pi_4_l = 2.167952532530945256199261006510837992190580836564132585443e-35L,
  63      -pi3_4 = 2.35619449019234492884698253745962709810930107360297167975337824L,
  64      -pi3_4_l = 6.503857597592835768597783019532513976571742509692397756331e-35L;
       56 +        E = 9.6296497219361792652798897129246365926905e-35L,    /* 2**-113 */
       57 +        pi = 3.1415926535897932384626433832795027974790680981372955730045043318L,
       58 +        pi_l = 8.6718101301237810247970440260433519687623233462565303417759356862e-35L,
       59 +        pi_2 = 1.5707963267948966192313216916397513987395340L,
       60 +        pi_2_l = 4.3359050650618905123985220130216759843811616e-35L,
       61 +        pi_4 = 0.785398163397448309615660845819875699369767024534323893251126L,
       62 +        pi_4_l = 2.167952532530945256199261006510837992190580836564132585443e-35L,
       63 +        pi3_4 = 2.35619449019234492884698253745962709810930107360297167975337824L,
       64 +        pi3_4_l = 6.503857597592835768597783019532513976571742509692397756331e-35L;
  65   65  #endif
  66      -/* INDENT ON */
       66 +/* END CSTYLED */
  67   67  
  68   68  #if defined(__x86)
  69   69  static const int ip1 = 0x40400000;      /* 2**65 */
  70   70  #else
  71   71  static const int ip1 = 0x40710000;      /* 2**114 */
  72   72  #endif
  73   73  
  74   74  ldcomplex
  75      -cacosl(ldcomplex z) {
       75 +cacosl(ldcomplex z)
       76 +{
  76   77          long double x, y, t, R, S, A, Am1, B, y2, xm1, xp1, Apx;
  77   78          int ix, iy, hx, hy;
  78   79          ldcomplex ans;
  79   80  
  80   81          x = LD_RE(z);
  81   82          y = LD_IM(z);
  82   83          hx = HI_XWORD(x);
  83   84          hy = HI_XWORD(y);
  84   85          ix = hx & 0x7fffffff;
  85   86          iy = hy & 0x7fffffff;
↓ open down ↓ 4 lines elided ↑ open up ↑
  90   91                          LD_RE(ans) = pi_2 + pi_2_l;
  91   92                          LD_IM(ans) = -y;
  92   93                          return (ans);
  93   94                  }
  94   95          }
  95   96  
  96   97          /* |y| is inf or NaN */
  97   98          if (iy >= 0x7fff0000) {
  98   99                  if (isinfl(y)) {        /* cacos(x + i inf) =  pi/2 - i inf */
  99  100                          LD_IM(ans) = -y;
      101 +
 100  102                          if (ix < 0x7fff0000) {
 101  103                                  LD_RE(ans) = pi_2 + pi_2_l;
 102  104                          } else if (isinfl(x)) {
 103  105                                  if (hx >= 0)
 104  106                                          LD_RE(ans) = pi_4 + pi_4_l;
 105  107                                  else
 106  108                                          LD_RE(ans) = pi3_4 + pi3_4_l;
 107  109                          } else {
 108  110                                  LD_RE(ans) = x;
 109  111                          }
 110  112                  } else {                /* cacos(x + i NaN) = NaN  + i NaN */
 111  113                          LD_RE(ans) = y + x;
      114 +
 112  115                          if (isinfl(x))
 113  116                                  LD_IM(ans) = -fabsl(x);
 114  117                          else
 115  118                                  LD_IM(ans) = y;
 116  119                  }
      120 +
 117  121                  return (ans);
 118  122          }
 119  123  
 120  124          y = fabsl(y);
 121  125  
 122      -        if (ix >= 0x7fff0000) { /* x is inf or NaN */
      126 +        if (ix >= 0x7fff0000) {         /* x is inf or NaN */
 123  127                  if (isinfl(x)) {        /* x is INF */
 124  128                          LD_IM(ans) = -fabsl(x);
      129 +
 125  130                          if (iy >= 0x7fff0000) {
 126  131                                  if (isinfl(y)) {
 127      -                                        /* INDENT OFF */
 128      -                                        /* cacos(inf + i inf) = pi/4 - i inf */
 129      -                                        /* cacos(-inf+ i inf) =3pi/4 - i inf */
 130      -                                        /* INDENT ON */
      132 +                                        /*
      133 +                                         * cacos(inf + i inf) = pi/4 - i inf
      134 +                                         * cacos(-inf+ i inf) =3pi/4 - i inf
      135 +                                         */
 131  136                                          if (hx >= 0)
 132  137                                                  LD_RE(ans) = pi_4 + pi_4_l;
 133  138                                          else
 134  139                                                  LD_RE(ans) = pi3_4 + pi3_4_l;
 135      -                                } else
 136      -                                        /* INDENT OFF */
 137      -                                        /* cacos(inf + i NaN) = NaN  - i inf  */
 138      -                                        /* INDENT ON */
      140 +                                } else {
      141 +                                        /*
      142 +                                         * cacos(inf + i NaN) = NaN  - i inf
      143 +                                         */
 139  144                                          LD_RE(ans) = y + y;
      145 +                                }
 140  146                          } else {
 141      -                                /* INDENT OFF */
 142      -                                /* cacos(inf + iy ) = 0  - i inf */
 143      -                                /* cacos(-inf+ iy  ) = pi - i inf */
 144      -                                /* INDENT ON */
      147 +                                /*
      148 +                                 * cacos(inf + iy ) = 0  - i inf
      149 +                                 * cacos(-inf+ iy  ) = pi - i inf
      150 +                                 */
 145  151                                  if (hx >= 0)
 146  152                                          LD_RE(ans) = zero;
 147  153                                  else
 148  154                                          LD_RE(ans) = pi + pi_l;
 149  155                          }
 150  156                  } else {                /* x is NaN */
 151      -                        /* INDENT OFF */
      157 +
 152  158                          /*
 153  159                           * cacos(NaN + i inf) = NaN  - i inf
 154  160                           * cacos(NaN + i y  ) = NaN  + i NaN
 155  161                           * cacos(NaN + i NaN) = NaN  + i NaN
 156  162                           */
 157      -                        /* INDENT ON */
 158  163                          LD_RE(ans) = x + y;
 159      -                        if (iy >= 0x7fff0000) {
      164 +
      165 +                        if (iy >= 0x7fff0000)
 160  166                                  LD_IM(ans) = -y;
 161      -                        } else {
      167 +                        else
 162  168                                  LD_IM(ans) = x;
 163      -                        }
 164  169                  }
      170 +
 165  171                  if (hy < 0)
 166  172                          LD_IM(ans) = -LD_IM(ans);
      173 +
 167  174                  return (ans);
 168  175          }
 169  176  
 170      -        if (y == zero) {        /* region 1: y=0 */
      177 +        if (y == zero) {                /* region 1: y=0 */
 171  178                  if (ix < 0x3fff0000) {  /* |x| < 1 */
 172  179                          LD_RE(ans) = acosl(x);
 173  180                          LD_IM(ans) = zero;
 174  181                  } else {
 175  182                          LD_RE(ans) = zero;
 176  183                          x = fabsl(x);
 177      -                        if (ix >= ip1)  /* i386 ? 2**65 : 2**114 */
      184 +
      185 +                        if (ix >= ip1) { /* i386 ? 2**65 : 2**114 */
 178  186                                  LD_IM(ans) = ln2 + logl(x);
 179      -                        else if (ix >= 0x3fff8000)      /* x > Acrossover */
      187 +                        } else if (ix >= 0x3fff8000) {  /* x > Acrossover */
 180  188                                  LD_IM(ans) = logl(x + sqrtl((x - one) * (x +
 181      -                                        one)));
 182      -                        else {
      189 +                                    one)));
      190 +                        } else {
 183  191                                  xm1 = x - one;
 184  192                                  LD_IM(ans) = log1pl(xm1 + sqrtl(xm1 * (x +
 185      -                                        one)));
      193 +                                    one)));
 186  194                          }
 187  195                  }
 188  196          } else if (y <= E * fabsl(fabsl(x) - one)) {
 189  197                  /* region 2: y < tiny*||x|-1| */
 190  198                  if (ix < 0x3fff0000) {  /* x < 1 */
 191  199                          LD_RE(ans) = acosl(x);
 192  200                          x = fabsl(x);
 193  201                          LD_IM(ans) = y / sqrtl((one + x) * (one - x));
 194  202                  } else if (ix >= ip1) { /* i386 ? 2**65 : 2**114 */
 195      -                        if (hx >= 0)
      203 +                        if (hx >= 0) {
 196  204                                  LD_RE(ans) = y / x;
 197      -                        else {
 198      -                                if (ix >= ip1 + 0x00040000)
      205 +                        } else {
      206 +                                if (ix >= ip1 + 0x00040000) {
 199  207                                          LD_RE(ans) = pi + pi_l;
 200      -                                else {
      208 +                                } else {
 201  209                                          t = pi_l + y / x;
 202  210                                          LD_RE(ans) = pi + t;
 203  211                                  }
 204  212                          }
      213 +
 205  214                          LD_IM(ans) = ln2 + logl(fabsl(x));
 206  215                  } else {
 207  216                          x = fabsl(x);
 208  217                          t = sqrtl((x - one) * (x + one));
 209      -                        LD_RE(ans) = (hx >= 0)? y / t : pi - (y / t - pi_l);
      218 +                        LD_RE(ans) = (hx >= 0) ? y / t : pi - (y / t - pi_l);
      219 +
 210  220                          if (ix >= 0x3fff8000)   /* x > Acrossover */
 211  221                                  LD_IM(ans) = logl(x + t);
 212  222                          else
 213  223                                  LD_IM(ans) = log1pl(t - (one - x));
 214  224                  }
 215  225          } else if (y < Foursqrtu) {     /* region 3 */
 216  226                  t = sqrtl(y);
 217      -                LD_RE(ans) = (hx >= 0)? t : pi + pi_l;
      227 +                LD_RE(ans) = (hx >= 0) ? t : pi + pi_l;
 218  228                  LD_IM(ans) = t;
 219  229          } else if (E * y - one >= fabsl(x)) {   /* region 4 */
 220  230                  LD_RE(ans) = pi_2 + pi_2_l;
 221  231                  LD_IM(ans) = ln2 + logl(y);
 222  232          } else if (ix >= 0x5ffb0000 || iy >= 0x5ffb0000) {
 223  233                  /* region 5: x+1 and y are both (>= sqrt(max)/8) i.e. 2**8188 */
 224  234                  t = x / y;
 225  235                  LD_RE(ans) = atan2l(y, x);
 226  236                  LD_IM(ans) = ln2 + logl(y) + half * log1pl(t * t);
 227  237          } else if (fabsl(x) < Foursqrtu) {
 228  238                  /* region 6: x is very small, < 4sqrt(min) */
 229  239                  LD_RE(ans) = pi_2 + pi_2_l;
 230  240                  A = sqrtl(one + y * y);
      241 +
 231  242                  if (iy >= 0x3fff8000)   /* if y > Acrossover */
 232  243                          LD_IM(ans) = logl(y + A);
 233  244                  else
 234  245                          LD_IM(ans) = half * log1pl((y + y) * (y + A));
 235      -        } else {        /* safe region */
      246 +        } else {                        /* safe region */
 236  247                  t = fabsl(x);
 237  248                  y2 = y * y;
 238  249                  xp1 = t + one;
 239  250                  xm1 = t - one;
 240  251                  R = sqrtl(xp1 * xp1 + y2);
 241  252                  S = sqrtl(xm1 * xm1 + y2);
 242  253                  A = half * (R + S);
 243  254                  B = t / A;
 244  255  
 245      -                if (B <= Bcrossover)
 246      -                        LD_RE(ans) = (hx >= 0)? acosl(B) : acosl(-B);
 247      -                else {          /* use atan and an accurate approx to a-x */
      256 +                if (B <= Bcrossover) {
      257 +                        LD_RE(ans) = (hx >= 0) ? acosl(B) : acosl(-B);
      258 +                } else {        /* use atan and an accurate approx to a-x */
 248  259                          Apx = A + t;
      260 +
 249  261                          if (t <= one)
 250  262                                  LD_RE(ans) = atan2l(sqrtl(half * Apx * (y2 /
 251      -                                        (R + xp1) + (S - xm1))), x);
      263 +                                    (R + xp1) + (S - xm1))), x);
 252  264                          else
 253  265                                  LD_RE(ans) = atan2l((y * sqrtl(half * (Apx /
 254      -                                        (R + xp1) + Apx / (S + xm1)))), x);
      266 +                                    (R + xp1) + Apx / (S + xm1)))), x);
 255  267                  }
      268 +
 256  269                  if (A <= Acrossover) {
 257  270                          /* use log1p and an accurate approx to A-1 */
 258  271                          if (ix < 0x3fff0000)
 259  272                                  Am1 = half * (y2 / (R + xp1) + y2 / (S - xm1));
 260  273                          else
 261  274                                  Am1 = half * (y2 / (R + xp1) + (S + xm1));
      275 +
 262  276                          LD_IM(ans) = log1pl(Am1 + sqrtl(Am1 * (A + one)));
 263  277                  } else {
 264  278                          LD_IM(ans) = logl(A + sqrtl(A * A - one));
 265  279                  }
 266  280          }
 267  281  
 268  282          if (hy >= 0)
 269  283                  LD_IM(ans) = -LD_IM(ans);
 270  284  
 271  285          return (ans);
 272  286  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX