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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/C/remainder.c
          +++ new/usr/src/lib/libm/common/C/remainder.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 __remainder = remainder
  30   32  
  31   33  /*
  32   34   * remainder(x,p)
  33   35   * Code originated from 4.3bsd.
  34   36   * Modified by K.C. Ng for SUN 4.0 libm.
  35   37   * Return :
  36      - *      returns  x REM p  =  x - [x/p]*p as if in infinite precise arithmetic,
       38 + *      returns  x REM p  =  x - [x/p]*p as if in infinite precise arithmetic,
  37   39   *      where [x/p] is the (inifinite bit) integer nearest x/p (in half way
  38   40   *      case choose the even one).
  39   41   * Method :
  40   42   *      Based on fmod() return x-[x/p]chopped*p exactly.
  41   43   */
  42   44  
  43   45  #include "libm.h"
  44   46  
  45   47  static const double zero = 0.0, half = 0.5;
  46   48  
  47   49  double
  48      -remainder(double x, double p) {
  49      -        double  halfp;
  50      -        int     ix, hx, hp;
       50 +remainder(double x, double p)
       51 +{
       52 +        double halfp;
       53 +        int ix, hx, hp;
  51   54  
  52   55          ix = ((int *)&x)[HIWORD];
  53   56          hx = ix & ~0x80000000;
  54   57          hp = ((int *)&p)[HIWORD] & ~0x80000000;
  55   58  
  56   59          if (hp > 0x7ff00000 || (hp == 0x7ff00000 && ((int *)&p)[LOWORD] != 0))
  57   60                  return (x * p);
       61 +
  58   62          if (hx > 0x7ff00000 || (hx == 0x7ff00000 && ((int *)&x)[LOWORD] != 0))
  59   63                  return (x * p);
  60   64  
  61   65          if ((hp | ((int *)&p)[LOWORD]) == 0 || hx == 0x7ff00000)
  62   66                  return (_SVID_libm_err(x, p, 28));
  63   67  
  64   68          p = fabs(p);
       69 +
  65   70          if (hp < 0x7fe00000)
  66   71                  x = fmod(x, p + p);
       72 +
  67   73          x = fabs(x);
       74 +
  68   75          if (hp < 0x00200000) {
  69   76                  if (x + x > p) {
  70   77                          if (x == p)     /* avoid x-x=-0 in RM mode */
  71      -                                return ((ix < 0)? -zero : zero);
       78 +                                return ((ix < 0) ? -zero : zero);
       79 +
  72   80                          x -= p;
       81 +
  73   82                          if (x + x >= p)
  74   83                                  x -= p;
  75   84                  }
  76   85          } else {
  77   86                  halfp = half * p;
       87 +
  78   88                  if (x > halfp) {
  79   89                          if (x == p)     /* avoid x-x=-0 in RM mode */
  80      -                                return ((ix < 0)? -zero : zero);
       90 +                                return ((ix < 0) ? -zero : zero);
       91 +
  81   92                          x -= p;
       93 +
  82   94                          if (x >= halfp)
  83   95                                  x -= p;
  84   96                  }
  85   97          }
  86      -        return ((ix < 0)? -x : x);
       98 +
       99 +        return ((ix < 0) ? -x : x);
  87  100  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX