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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/Q/hypotl.c
          +++ new/usr/src/lib/libm/common/Q/hypotl.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 __hypotl = hypotl
  31   32  
  32   33  /*
  33   34   * long double hypotl(long double x, long double y);
  34   35   * Method :
↓ open down ↓ 10 lines elided ↑ open up ↑
  45   46   *      where t1 = 2x with lower 64 bits cleared, t2 = 2x-t1, y1= y with
  46   47   *      lower 64 bits chopped, y2 = y-y1.
  47   48   *
  48   49   *      NOTE: DO NOT remove parenthsis!
  49   50   *
  50   51   * Special cases:
  51   52   *      hypot(x,y) is INF if x or y is +INF or -INF; else
  52   53   *      hypot(x,y) is NAN if x or y is NAN.
  53   54   *
  54   55   * Accuracy:
  55      - *      hypot(x,y) returns sqrt(x^2+y^2) with error less than 1 ulps (units
       56 + *      hypot(x,y) returns sqrt(x^2+y^2) with error less than 1 ulps (units
  56   57   *      in the last place)
  57   58   */
  58   59  
  59   60  #include "libm.h"
  60   61  #include "longdouble.h"
  61   62  
  62   63  extern enum fp_direction_type __swapRD(enum fp_direction_type);
  63   64  
  64   65  static const long double zero = 0.0L, one = 1.0L;
  65      -
  66   66  long double
  67      -hypotl(long double x, long double y) {
       67 +hypotl(long double x, long double y)
       68 +{
  68   69          int n0, n1, n2, n3;
  69   70          long double t1, t2, y1, y2, w;
  70      -        int *px = (int *) &x, *py = (int *) &y;
  71      -        int *pt1 = (int *) &t1, *py1 = (int *) &y1;
       71 +        int *px = (int *)&x, *py = (int *)&y;
       72 +        int *pt1 = (int *)&t1, *py1 = (int *)&y1;
  72   73          enum fp_direction_type rd;
  73   74          int j, k, nx, ny, nz;
  74   75  
  75      -        if ((*(int *) &one) != 0) {     /* determine word ordering */
       76 +        if ((*(int *)&one) != 0) {      /* determine word ordering */
  76   77                  n0 = 0;
  77   78                  n1 = 1;
  78   79                  n2 = 2;
  79   80                  n3 = 3;
  80   81          } else {
  81   82                  n0 = 3;
  82   83                  n1 = 2;
  83   84                  n2 = 1;
  84   85                  n3 = 0;
  85   86          }
  86   87  
  87      -        px[n0] &= 0x7fffffff;   /* clear sign bit of x and y */
       88 +        px[n0] &= 0x7fffffff;           /* clear sign bit of x and y */
  88   89          py[n0] &= 0x7fffffff;
  89   90          k = 0x7fff0000;
  90      -        nx = px[n0] & k;        /* exponent of x and y */
       91 +        nx = px[n0] & k;                /* exponent of x and y */
  91   92          ny = py[n0] & k;
       93 +
  92   94          if (ny > nx) {
  93   95                  w = x;
  94   96                  x = y;
  95   97                  y = w;
  96   98                  nz = ny;
  97   99                  ny = nx;
  98  100                  nx = nz;
  99      -        }                       /* force x > y */
      101 +        }                               /* force x > y */
      102 +
 100  103          if ((nx - ny) >= 0x00730000)
 101  104                  return (x + y); /* x/y >= 2**116 */
      105 +
 102  106          if (nx < 0x5ff30000 && ny > 0x205b0000) {       /* medium x,y */
 103  107                  /* save and set RD to Rounding to nearest */
 104  108                  rd = __swapRD(fp_nearest);
 105  109                  w = x - y;
      110 +
 106  111                  if (w > y) {
 107  112                          pt1[n0] = px[n0];
 108  113                          pt1[n1] = px[n1];
 109  114                          pt1[n2] = pt1[n3] = 0;
 110  115                          t2 = x - t1;
 111  116                          x = sqrtl(t1 * t1 - (y * (-y) - t2 * (x + t1)));
 112  117                  } else {
 113  118                          x = x + x;
 114  119                          py1[n0] = py[n0];
 115  120                          py1[n1] = py[n1];
 116  121                          py1[n2] = py1[n3] = 0;
 117  122                          y2 = y - y1;
 118  123                          pt1[n0] = px[n0];
 119  124                          pt1[n1] = px[n1];
 120  125                          pt1[n2] = pt1[n3] = 0;
 121  126                          t2 = x - t1;
 122  127                          x = sqrtl(t1 * y1 - (w * (-w) - (t2 * y1 + y2 * x)));
 123  128                  }
      129 +
 124  130                  if (rd != fp_nearest)
 125  131                          (void) __swapRD(rd);    /* restore rounding mode */
      132 +
 126  133                  return (x);
 127  134          } else {
 128  135                  if (nx == k || ny == k) {       /* x or y is INF or NaN */
 129  136                          if (isinfl(x))
 130  137                                  t2 = x;
 131  138                          else if (isinfl(y))
 132  139                                  t2 = y;
 133  140                          else
 134  141                                  t2 = x + y;     /* invalid if x or y is sNaN */
      142 +
 135  143                          return (t2);
 136  144                  }
      145 +
 137  146                  if (ny == 0) {
 138  147                          if (y == zero || x == zero)
 139  148                                  return (x + y);
      149 +
 140  150                          t1 = scalbnl(one, 16381);
 141  151                          x *= t1;
 142  152                          y *= t1;
 143  153                          return (scalbnl(one, -16381) * hypotl(x, y));
 144  154                  }
      155 +
 145  156                  j = nx - 0x3fff0000;
 146  157                  px[n0] -= j;
 147  158                  py[n0] -= j;
 148  159                  pt1[n0] = nx;
 149  160                  pt1[n1] = pt1[n2] = pt1[n3] = 0;
 150  161                  return (t1 * hypotl(x, y));
 151  162          }
 152  163  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX