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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/C/fmod.c
          +++ new/usr/src/lib/libm/common/C/fmod.c
↓ open down ↓ 10 lines elided ↑ open up ↑
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  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   * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  23   24   */
       25 +
  24   26  /*
  25   27   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  26   28   * Use is subject to license terms.
  27   29   */
  28   30  
  29   31  #pragma weak __fmod = fmod
  30   32  
  31   33  #include "libm.h"
  32   34  
  33   35  static const double zero = 0.0;
  34   36  
  35   37  /*
  36   38   * The following implementation assumes fast 64-bit integer arith-
  37   39   * metic.  This is fine for sparc because we build libm in v8plus
  38   40   * mode.  It's also fine for sparcv9 and amd64, although we have
  39   41   * assembly code on amd64.  For x86, it would be better to use
  40   42   * 32-bit code, but we have assembly for x86, too.
  41   43   */
  42   44  double
  43      -fmod(double x, double y) {
  44      -        double          w;
  45      -        long long       hx, ix, iy, iz;
  46      -        int             nd, k, ny;
       45 +fmod(double x, double y)
       46 +{
       47 +        double w;
       48 +        long long hx, ix, iy, iz;
       49 +        int nd, k, ny;
  47   50  
  48   51          hx = *(long long *)&x;
  49   52          ix = hx & ~0x8000000000000000ull;
  50   53          iy = *(long long *)&y & ~0x8000000000000000ull;
  51   54  
  52   55          /* handle special cases */
  53   56          if (iy == 0ll)
  54   57                  return (_SVID_libm_err(x, y, 27));
  55   58  
  56   59          if (ix >= 0x7ff0000000000000ll || iy > 0x7ff0000000000000ll)
  57   60                  return ((x * y) * zero);
  58   61  
  59   62          if (ix <= iy)
  60      -                return ((ix < iy)? x : x * zero);
       63 +                return ((ix < iy) ? x : x *zero);
  61   64  
  62   65          /*
  63   66           * Set:
  64   67           *      ny = true exponent of y
  65   68           *      nd = true exponent of x minus true exponent of y
  66   69           *      ix = normalized significand of x
  67   70           *      iy = normalized significand of y
  68   71           */
  69   72          ny = iy >> 52;
  70   73          k = ix >> 52;
       74 +
  71   75          if (ny == 0) {
  72   76                  /* y is subnormal, x could be normal or subnormal */
  73   77                  ny = 1;
       78 +
  74   79                  while (iy < 0x0010000000000000ll) {
  75   80                          ny -= 1;
  76   81                          iy += iy;
  77   82                  }
       83 +
  78   84                  nd = k - ny;
       85 +
  79   86                  if (k == 0) {
  80   87                          nd += 1;
       88 +
  81   89                          while (ix < 0x0010000000000000ll) {
  82   90                                  nd -= 1;
  83   91                                  ix += ix;
  84   92                          }
  85   93                  } else {
  86   94                          ix = 0x0010000000000000ll | (ix & 0x000fffffffffffffll);
  87   95                  }
  88   96          } else {
  89   97                  /* both x and y are normal */
  90   98                  nd = k - ny;
  91   99                  ix = 0x0010000000000000ll | (ix & 0x000fffffffffffffll);
  92  100                  iy = 0x0010000000000000ll | (iy & 0x000fffffffffffffll);
  93  101          }
  94  102  
  95  103          /* perform fixed point mod */
  96  104          while (nd--) {
  97  105                  iz = ix - iy;
      106 +
  98  107                  if (iz >= 0)
  99  108                          ix = iz;
      109 +
 100  110                  ix += ix;
 101  111          }
      112 +
 102  113          iz = ix - iy;
      114 +
 103  115          if (iz >= 0)
 104  116                  ix = iz;
 105  117  
 106  118          /* convert back to floating point and restore the sign */
 107  119          if (ix == 0ll)
 108  120                  return (x * zero);
      121 +
 109  122          while (ix < 0x0010000000000000ll) {
 110  123                  ix += ix;
 111  124                  ny -= 1;
 112  125          }
      126 +
 113  127          while (ix > 0x0020000000000000ll) {     /* XXX can this ever happen? */
 114  128                  ny += 1;
 115  129                  ix >>= 1;
 116  130          }
      131 +
 117  132          if (ny <= 0) {
 118  133                  /* result is subnormal */
 119  134                  k = -ny + 1;
 120  135                  ix >>= k;
 121      -                *(long long *)&w = (hx & 0x8000000000000000ull) | ix;
      136 +                *(long long *) &w = (hx & 0x8000000000000000ull) | ix;
 122  137                  return (w);
 123  138          }
 124      -        *(long long *)&w = (hx & 0x8000000000000000ull) |
 125      -            ((long long)ny << 52) | (ix & 0x000fffffffffffffll);
      139 +
      140 +        *(long long *) &w = (hx & 0x8000000000000000ull) | ((long long)ny <<
      141 +            52) | (ix & 0x000fffffffffffffll);
 126  142          return (w);
 127  143  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX