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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/R/rintf.c
          +++ new/usr/src/lib/libm/common/R/rintf.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 __rintf = rintf
  31   32  
  32      -/* INDENT OFF */
       33 +
  33   34  /*
  34   35   * aintf(x)     return x chopped to integral value
  35   36   * anintf(x)    return sign(x)*(|x|+0.5) chopped to integral value
  36   37   * irintf(x)    return rint(x) in integer format
  37   38   * nintf(x)     return anint(x) in integer format
  38   39   * rintf(x)     return x rounded to integral according to the rounding direction
  39   40   *
  40   41   * NOTE: rintf(x), aintf(x) and anintf(x) return results with the same sign as
  41   42   * x's,  including 0.0.
  42   43   */
  43   44  
  44   45  #include "libm.h"
  45   46  
  46   47  static const float xf[] = {
  47      -/* ZEROF */     0.0f,
  48      -/* TWO_23F */   8.3886080000e6f,
  49      -/* MTWO_23F */  -8.3886080000e6f,
  50      -/* ONEF */      1.0f,
  51      -/* MONEF */     -1.0f,
  52      -/* HALFF */     0.5f,
  53      -/* MHALFF */    -0.5f,
  54      -/* HUGEF */     1.0e30f,
       48 +/* ZEROF */
       49 +        0.0f,
       50 +/* TWO_23F */ 8.3886080000e6f,
       51 +/* MTWO_23F */ -8.3886080000e6f,
       52 +/* ONEF */ 1.0f,
       53 +/* MONEF */ -1.0f,
       54 +/* HALFF */ 0.5f,
       55 +/* MHALFF */ -0.5f,
       56 +/* HUGEF */ 1.0e30f,
  55   57  };
  56   58  
  57   59  #define ZEROF           xf[0]
  58   60  #define TWO_23F         xf[1]
  59   61  #define MTWO_23F        xf[2]
  60   62  #define ONEF            xf[3]
  61   63  #define MONEF           xf[4]
  62   64  #define HALFF           xf[5]
  63   65  #define MHALFF          xf[6]
  64   66  #define HUGEF           xf[7]
  65      -/* INDENT ON */
  66   67  
  67   68  float
  68      -aintf(float x) {
       69 +aintf(float x)
       70 +{
  69   71          int hx, k;
  70   72          float y;
  71   73  
  72      -        hx = *(int *) &x;
       74 +        hx = *(int *)&x;
  73   75          k = (hx & ~0x80000000) >> 23;
       76 +
  74   77          if (k < 150) {
  75      -                y = (float) ((int) x);
       78 +                y = (float)((int)x);
       79 +
  76   80                  /*
  77   81                   * make sure y has the same sign of x when |x|<0.5
  78   82                   * (i.e., y=0.0)
  79   83                   */
  80   84                  return (((k - 127) & hx) < 0 ? -y : y);
  81      -        } else
       85 +        } else {
  82   86                  /* signal invalid if x is a SNaN */
  83      -                return (x * ONEF);              /* +0 -> *1 for Cheetah */
       87 +                return (x * ONEF);      /* +0 -> *1 for Cheetah */
       88 +        }
  84   89  }
  85   90  
  86   91  float
  87      -anintf(float x) {
       92 +anintf(float x)
       93 +{
  88   94          volatile float dummy __unused;
  89   95          int hx, k, j, ix;
  90   96  
  91      -        hx = *(int *) &x;
       97 +        hx = *(int *)&x;
  92   98          ix = hx & ~0x80000000;
  93   99          k = ix >> 23;
      100 +
  94  101          if (((k - 127) ^ (k - 150)) < 0) {
  95  102                  j = 1 << (149 - k);
  96  103                  k = j + j - 1;
      104 +
  97  105                  if ((k & hx) != 0)
  98  106                          dummy = HUGEF + x;      /* raise inexact */
  99      -                *(int *) &x = (hx + j) & ~k;
      107 +
      108 +                *(int *)&x = (hx + j) & ~k;
 100  109                  return (x);
 101  110          } else if (k <= 126) {
 102  111                  dummy = HUGEF + x;
 103      -                *(int *) &x = (0x3f800000 & ((125 - k) >> 31)) |
 104      -                        (0x80000000 & hx);
      112 +                *(int *)&x = (0x3f800000 & ((125 - k) >> 31)) |
      113 +                    (0x80000000 & hx);
 105  114                  return (x);
 106      -        } else
      115 +        } else {
 107  116                  /* signal invalid if x is a SNaN */
 108      -                return (x * ONEF);              /* +0 -> *1 for Cheetah */
      117 +                return (x * ONEF);      /* +0 -> *1 for Cheetah */
      118 +        }
 109  119  }
 110  120  
 111  121  int
 112      -irintf(float x) {
      122 +irintf(float x)
      123 +{
 113  124          float v;
 114  125          int hx, k;
 115  126  
 116      -        hx = *(int *) &x;
      127 +        hx = *(int *)&x;
 117  128          k = (hx & ~0x80000000) >> 23;
 118  129          v = xf[((k - 150) >> 31) & (1 - (hx >> 31))];
 119      -        return ((int) ((float) (x + v) - v));
      130 +        return ((int)((float)(x + v) - v));
 120  131  }
 121  132  
 122  133  int
 123      -nintf(float x) {
      134 +nintf(float x)
      135 +{
 124  136          int hx, ix, k, j, m;
 125  137          volatile float dummy __unused;
 126  138  
 127      -        hx = *(int *) &x;
      139 +        hx = *(int *)&x;
 128  140          k = (hx & ~0x80000000) >> 23;
      141 +
 129  142          if (((k - 126) ^ (k - 150)) < 0) {
 130  143                  ix = (hx & 0x00ffffff) | 0x800000;
 131  144                  m = 149 - k;
 132  145                  j = 1 << m;
      146 +
 133  147                  if ((ix & (j + j - 1)) != 0)
 134  148                          dummy = HUGEF + x;
      149 +
 135  150                  hx = hx >> 31;
 136  151                  return ((((ix + j) >> (m + 1)) ^ hx) - hx);
 137      -        } else
 138      -                return ((int) x);
      152 +        } else {
      153 +                return ((int)x);
      154 +        }
 139  155  }
 140  156  
 141  157  float
 142      -rintf(float x) {
      158 +rintf(float x)
      159 +{
 143  160          float w, v;
 144  161          int hx, k;
 145  162  
 146      -        hx = *(int *) &x;
      163 +        hx = *(int *)&x;
 147  164          k = (hx & ~0x80000000) >> 23;
 148  165  #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
 149  166          if (k >= 150)
 150  167                  return (x * ONEF);
      168 +
 151  169          v = xf[1 - (hx >> 31)];
 152  170  #else
 153  171          v = xf[((k - 150) >> 31) & (1 - (hx >> 31))];
 154  172  #endif
 155      -        w = (float) (x + v);
      173 +        w = (float)(x + v);
      174 +
 156  175          if (k < 127 && w == v)
 157  176                  return (ZEROF * x);
 158  177          else
 159  178                  return (w - v);
 160  179  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX