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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/m9x/roundl.c
          +++ new/usr/src/lib/libm/common/m9x/roundl.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 __roundl = roundl
  31   32  
  32   33  #include "libm.h"
  33   34  
  34   35  #if defined(__sparc)
  35   36  long double
  36      -roundl(long double x) {
       37 +roundl(long double x)
       38 +{
  37   39          union {
  38   40                  unsigned i[4];
  39   41                  long double q;
  40   42          } xx;
       43 +
  41   44          unsigned hx, sx, v;
  42   45          int j;
  43   46  
  44   47          xx.q = x;
  45   48          sx = xx.i[0] & 0x80000000;
  46   49          hx = xx.i[0] & ~0x80000000;
  47   50  
  48   51          /* handle trivial cases */
  49      -        if (hx >= 0x406f0000) /* |x| >= 2^112 + ... or x is nan */
       52 +        if (hx >= 0x406f0000)           /* |x| >= 2^112 + ... or x is nan */
  50   53                  return (hx >= 0x7fff0000 ? x + x : x);
  51   54  
  52   55          /* handle |x| < 1 */
  53   56          if (hx < 0x3fff0000) {
  54   57                  if (hx >= 0x3ffe0000)
  55   58                          return (sx ? -1.0L : 1.0L);
       59 +
  56   60                  return (sx ? -0.0L : 0.0L);
  57   61          }
  58   62  
  59   63          xx.i[0] = hx;
  60      -        j = 0x406f - (hx >> 16);                /* 1 <= j <= 112 */
  61      -        if (j >= 96) {                          /* 96 <= j <= 112 */
       64 +        j = 0x406f - (hx >> 16);        /* 1 <= j <= 112 */
       65 +
       66 +        if (j >= 96) {                  /* 96 <= j <= 112 */
  62   67                  v = (1U << (j - 96)) >> 1;
       68 +
  63   69                  if (v) {
  64   70                          if (xx.i[0] & v)
  65   71                                  xx.i[0] += v;
       72 +
  66   73                          xx.i[0] &= ~(v - 1);
  67      -                } else if (xx.i[1] & 0x80000000)
  68      -                                ++xx.i[0];
       74 +                } else if (xx.i[1] & 0x80000000) {
       75 +                        ++xx.i[0];
       76 +                }
       77 +
  69   78                  xx.i[1] = xx.i[2] = xx.i[3] = 0;
  70      -        } else if (j >= 64) {                   /* 64 <= j <= 95 */
       79 +        } else if (j >= 64) {           /* 64 <= j <= 95 */
  71   80                  v = (1U << (j - 64)) >> 1;
       81 +
  72   82                  if (v) {
  73   83                          if (xx.i[1] & v) {
  74   84                                  xx.i[1] += v;
       85 +
  75   86                                  if (xx.i[1] < v)
  76   87                                          ++xx.i[0];
  77   88                          }
       89 +
  78   90                          xx.i[1] &= ~(v - 1);
  79   91                  } else if (xx.i[2] & 0x80000000) {
  80      -                                if (++xx.i[1] == 0)
  81      -                                        ++xx.i[0];
       92 +                        if (++xx.i[1] == 0)
       93 +                                ++xx.i[0];
  82   94                  }
       95 +
  83   96                  xx.i[2] = xx.i[3] = 0;
  84      -        } else if (j >= 32) {                   /* 32 <= j <= 63 */
       97 +        } else if (j >= 32) {           /* 32 <= j <= 63 */
  85   98                  v = (1U << (j - 32)) >> 1;
       99 +
  86  100                  if (v) {
  87  101                          if (xx.i[2] & v) {
  88  102                                  xx.i[2] += v;
      103 +
  89  104                                  if (xx.i[2] < v) {
  90  105                                          if (++xx.i[1] == 0)
  91  106                                                  ++xx.i[0];
  92  107                                  }
  93  108                          }
      109 +
  94  110                          xx.i[2] &= ~(v - 1);
  95  111                  } else if (xx.i[3] & 0x80000000) {
  96      -                                if (++xx.i[2] == 0) {
  97      -                                        if (++xx.i[1] == 0)
  98      -                                                ++xx.i[0];
  99      -                                }
      112 +                        if (++xx.i[2] == 0) {
      113 +                                if (++xx.i[1] == 0)
      114 +                                        ++xx.i[0];
      115 +                        }
 100  116                  }
      117 +
 101  118                  xx.i[3] = 0;
 102      -        } else {                                /* 1 <= j <= 31 */
      119 +        } else {                        /* 1 <= j <= 31 */
 103  120                  v = 1U << (j - 1);
      121 +
 104  122                  if (xx.i[3] & v) {
 105  123                          xx.i[3] += v;
      124 +
 106  125                          if (xx.i[3] < v) {
 107  126                                  if (++xx.i[2] == 0) {
 108  127                                          if (++xx.i[1] == 0)
 109  128                                                  ++xx.i[0];
 110  129                                  }
 111  130                          }
 112  131                  }
      132 +
 113  133                  xx.i[3] &= ~(v - 1);
 114  134          }
 115  135  
 116  136          /* negate result if need be */
 117  137          if (sx)
 118  138                  xx.i[0] |= 0x80000000;
      139 +
 119  140          return (xx.q);
 120  141  }
 121  142  #elif defined(__x86)
 122  143  long double
 123      -roundl(long double x) {
      144 +roundl(long double x)
      145 +{
 124  146          union {
 125  147                  unsigned i[3];
 126  148                  long double e;
 127  149          } xx;
      150 +
 128  151          int ex, sx, i;
 129  152  
 130  153          xx.e = x;
 131  154          ex = xx.i[2] & 0x7fff;
 132  155          sx = xx.i[2] & 0x8000;
 133      -        if (ex < 0x403e) {      /* |x| < 2^63 */
      156 +
      157 +        if (ex < 0x403e) {              /* |x| < 2^63 */
 134  158                  if (ex < 0x3fff) {      /* |x| < 1 */
 135  159                          if (ex >= 0x3ffe)
 136  160                                  return (sx ? -1.0L : 1.0L);
      161 +
 137  162                          return (sx ? -0.0L : 0.0L);
 138  163                  }
 139  164  
 140  165                  /* round x at the integer bit */
 141  166                  if (ex < 0x401e) {
 142  167                          i = 1 << (0x401d - ex);
 143  168                          xx.i[1] = (xx.i[1] + i) & ~(i | (i - 1));
 144  169                          xx.i[0] = 0;
 145  170                  } else {
 146  171                          i = 1 << (0x403d - ex);
 147  172                          xx.i[0] += i;
      173 +
 148  174                          if (xx.i[0] < i)
 149  175                                  xx.i[1]++;
      176 +
 150  177                          xx.i[0] &= ~(i | (i - 1));
 151  178                  }
      179 +
 152  180                  if (xx.i[1] == 0) {
 153  181                          xx.i[2] = sx | ++ex;
 154  182                          xx.i[1] = 0x80000000U;
 155  183                  }
      184 +
 156  185                  return (xx.e);
 157      -        } else if (ex < 0x7fff) /* x is integral */
      186 +        } else if (ex < 0x7fff) {       /* x is integral */
 158  187                  return (x);
 159      -        else                    /* inf or nan */
      188 +        } else {                        /* inf or nan */
 160  189                  return (x + x);
      190 +        }
 161  191  }
 162  192  #else
 163  193  #error Unknown architecture
 164      -#endif  /* defined(__sparc) || defined(__x86) */
      194 +#endif /* defined(__sparc) || defined(__x86) */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX