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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/m9x/nexttoward.c
          +++ new/usr/src/lib/libm/common/m9x/nexttoward.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 nexttoward = __nexttoward
  31   32  
  32   33  /*
  33   34   * nexttoward(x, y) delivers the next representable number after x
  34   35   * in the direction of y.  If x and y are both zero, the result is
↓ open down ↓ 1 lines elided ↑ open up ↑
  36   37   * is NaN.
  37   38   *
  38   39   * If x != y and the result is infinite, overflow is raised; if
  39   40   * x != y and the result is subnormal or zero, underflow is raised.
  40   41   * (This is wrong, but it's what C99 apparently wants.)
  41   42   */
  42   43  
  43   44  #include "libm.h"
  44   45  
  45   46  #if defined(__sparc)
  46      -
  47   47  static union {
  48   48          unsigned i[2];
  49   49          double d;
  50   50  } C[] = {
  51      -        0x00100000, 0,
  52      -        0x7fe00000, 0,
  53      -        0x7fffffff, 0xffffffff
       51 +        0x00100000, 0, 0x7fe00000, 0, 0x7fffffff, 0xffffffff
  54   52  };
  55   53  
  56      -#define tiny    C[0].d
  57      -#define huge    C[1].d
  58      -#define qnan    C[2].d
       54 +#define tiny            C[0].d
       55 +#define huge            C[1].d
       56 +#define qnan            C[2].d
  59   57  
  60   58  enum fcc_type {
  61      -        fcc_equal = 0,
  62      -        fcc_less = 1,
  63      -        fcc_greater = 2,
  64      -        fcc_unordered = 3
       59 +        fcc_equal = 0, fcc_less = 1, fcc_greater = 2, fcc_unordered = 3
  65   60  };
  66   61  
  67   62  #ifdef __sparcv9
  68      -#define _Q_cmp  _Qp_cmp
       63 +#define _Q_cmp          _Qp_cmp
  69   64  #endif
  70   65  
  71   66  extern enum fcc_type _Q_cmp(const long double *, const long double *);
  72   67  
  73   68  double
  74      -__nexttoward(double x, long double y) {
       69 +__nexttoward(double x, long double y)
       70 +{
  75   71          union {
  76   72                  unsigned i[2];
  77   73                  double d;
  78   74          } xx;
  79   75          union {
  80   76                  unsigned i[4];
  81   77                  long double q;
  82   78          } yy;
       79 +
  83   80          long double lx;
  84   81          unsigned hx;
  85      -        volatile double dummy;
       82 +        volatile double dummy;
  86   83          enum fcc_type rel;
  87   84  
  88   85          /*
  89   86           * It would be somewhat more efficient to check for NaN and
  90   87           * zero operands before converting x to long double and then
  91   88           * to code the comparison in line rather than calling _Q_cmp.
  92   89           * However, since this code probably won't get used much,
  93   90           * I'm opting in favor of simplicity instead.
  94   91           */
  95   92          lx = xx.d = x;
  96   93          hx = (xx.i[0] & ~0x80000000) | xx.i[1];
  97   94  
  98   95          /* check for each of four possible orderings */
  99   96          rel = _Q_cmp(&lx, &y);
       97 +
 100   98          if (rel == fcc_unordered)
 101   99                  return (qnan);
 102  100  
 103  101          if (rel == fcc_equal) {
 104  102                  if (hx == 0) {  /* x is zero; return zero with y's sign */
 105  103                          yy.q = y;
 106  104                          xx.i[0] = yy.i[0];
 107  105                          return (xx.d);
 108  106                  }
      107 +
 109  108                  return (x);
 110  109          }
 111  110  
 112  111          if (rel == fcc_less) {
 113      -                if (hx == 0) {  /* x is zero */
      112 +                if (hx == 0) {                  /* x is zero */
 114  113                          xx.i[0] = 0;
 115  114                          xx.i[1] = 0x00000001;
 116  115                  } else if ((int)xx.i[0] >= 0) { /* x is positive */
 117  116                          if (++xx.i[1] == 0)
 118  117                                  xx.i[0]++;
 119  118                  } else {
 120  119                          if (xx.i[1]-- == 0)
 121  120                                  xx.i[0]--;
 122  121                  }
 123  122          } else {
 124      -                if (hx == 0) {  /* x is zero */
      123 +                if (hx == 0) {                  /* x is zero */
 125  124                          xx.i[0] = 0x80000000;
 126  125                          xx.i[1] = 0x00000001;
 127  126                  } else if ((int)xx.i[0] >= 0) { /* x is positive */
 128  127                          if (xx.i[1]-- == 0)
 129  128                                  xx.i[0]--;
 130  129                  } else {
 131  130                          if (++xx.i[1] == 0)
 132  131                                  xx.i[0]++;
 133  132                  }
 134  133          }
 135  134  
 136  135          /* raise exceptions as needed */
 137  136          hx = xx.i[0] & ~0x80000000;
      137 +
 138  138          if (hx == 0x7ff00000) {
 139  139                  dummy = huge;
 140  140                  dummy *= huge;
 141  141          } else if (hx < 0x00100000) {
 142  142                  dummy = tiny;
 143  143                  dummy *= tiny;
 144  144          }
 145  145  
 146  146          return (xx.d);
 147  147  }
 148      -
 149  148  #elif defined(__x86)
 150      -
 151  149  static union {
 152  150          unsigned i[2];
 153  151          double d;
 154  152  } C[] = {
 155      -        0, 0x00100000,
 156      -        0, 0x7fe00000,
 157      -};
      153 +        0, 0x00100000, 0, 0x7fe00000, };
 158  154  
 159      -#define tiny    C[0].d
 160      -#define huge    C[1].d
      155 +#define tiny            C[0].d
      156 +#define huge            C[1].d
 161  157  
 162  158  double
 163      -__nexttoward(double x, long double y) {
      159 +__nexttoward(double x, long double y)
      160 +{
 164  161          union {
 165  162                  unsigned i[2];
 166  163                  double d;
 167  164          } xx;
      165 +
 168  166          unsigned hx;
 169  167          long double lx;
 170      -        volatile double dummy;
      168 +        volatile double dummy;
 171  169  
 172  170          lx = xx.d = x;
 173  171          hx = (xx.i[1] & ~0x80000000) | xx.i[0];
 174  172  
 175  173          /* check for each of four possible orderings */
 176  174          if (isunordered(lx, y))
 177      -                return ((double) (lx + y));
      175 +                return ((double)(lx + y));
 178  176  
 179  177          if (lx == y)
 180      -                return ((double) y);
      178 +                return ((double)y);
 181  179  
 182  180          if (lx < y) {
 183      -                if (hx == 0) {  /* x is zero */
      181 +                if (hx == 0) {                  /* x is zero */
 184  182                          xx.i[0] = 0x00000001;
 185  183                          xx.i[1] = 0;
 186  184                  } else if ((int)xx.i[1] >= 0) { /* x is positive */
 187  185                          if (++xx.i[0] == 0)
 188  186                                  xx.i[1]++;
 189  187                  } else {
 190  188                          if (xx.i[0]-- == 0)
 191  189                                  xx.i[1]--;
 192  190                  }
 193  191          } else {
 194      -                if (hx == 0) {  /* x is zero */
      192 +                if (hx == 0) {                  /* x is zero */
 195  193                          xx.i[0] = 0x00000001;
 196  194                          xx.i[1] = 0x80000000;
 197  195                  } else if ((int)xx.i[1] >= 0) { /* x is positive */
 198  196                          if (xx.i[0]-- == 0)
 199  197                                  xx.i[1]--;
 200  198                  } else {
 201  199                          if (++xx.i[0] == 0)
 202  200                                  xx.i[1]++;
 203  201                  }
 204  202          }
 205  203  
 206  204          /* raise exceptions as needed */
 207  205          hx = xx.i[1] & ~0x80000000;
      206 +
 208  207          if (hx == 0x7ff00000) {
 209  208                  dummy = huge;
 210  209                  dummy *= huge;
 211  210          } else if (hx < 0x00100000) {
 212  211                  dummy = tiny;
 213  212                  dummy *= tiny;
 214  213          }
 215  214  
 216  215          return (xx.d);
 217  216  }
 218      -
 219  217  #else
 220  218  #error Unknown architecture
 221  219  #endif
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX