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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/m9x/nearbyint.c
          +++ new/usr/src/lib/libm/common/m9x/nearbyint.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 nearbyint = __nearbyint
  31   32  
  32   33  /*
  33   34   * nearbyint(x) returns the nearest fp integer to x in the direction
  34   35   * corresponding to the current rounding direction without raising
  35   36   * the inexact exception.
  36   37   *
  37   38   * nearbyint(x) is x unchanged if x is +/-0 or +/-inf.  If x is NaN,
  38   39   * nearbyint(x) is also NaN.
  39   40   */
  40   41  
  41   42  #include "libm.h"
  42   43  #include <fenv.h>
  43   44  
  44   45  double
  45      -__nearbyint(double x) {
       46 +__nearbyint(double x)
       47 +{
  46   48          union {
  47   49                  unsigned i[2];
  48   50                  double d;
  49   51          } xx;
       52 +
  50   53          unsigned hx, sx, i, frac;
  51   54          int rm, j;
  52   55  
  53   56          xx.d = x;
  54   57          sx = xx.i[HIWORD] & 0x80000000;
  55   58          hx = xx.i[HIWORD] & ~0x80000000;
  56   59  
  57   60          /* handle trivial cases */
  58      -        if (hx >= 0x43300000) { /* x is nan, inf, or already integral */
       61 +        if (hx >= 0x43300000) {         /* x is nan, inf, or already integral */
  59   62                  if (hx >= 0x7ff00000)   /* x is inf or nan */
  60   63  #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
  61   64                          return (hx >= 0x7ff80000 ? x : x + x);
  62      -                        /* assumes sparc-like QNaN */
       65 +
       66 +                /* assumes sparc-like QNaN */
  63   67  #else
  64   68                          return (x + x);
  65   69  #endif
  66   70                  return (x);
  67      -        } else if ((hx | xx.i[LOWORD]) == 0)    /* x is zero */
       71 +        } else if ((hx | xx.i[LOWORD]) == 0) {  /* x is zero */
  68   72                  return (x);
       73 +        }
  69   74  
  70   75          /* get the rounding mode */
  71   76          rm = fegetround();
  72   77  
  73   78          /* flip the sense of directed roundings if x is negative */
  74   79          if (sx && (rm == FE_UPWARD || rm == FE_DOWNWARD))
  75   80                  rm = (FE_UPWARD + FE_DOWNWARD) - rm;
  76   81  
  77   82          /* handle |x| < 1 */
  78   83          if (hx < 0x3ff00000) {
  79      -                if (rm == FE_UPWARD || (rm == FE_TONEAREST &&
  80      -                        (hx >= 0x3fe00000 && ((hx & 0xfffff) | xx.i[LOWORD]))))
       84 +                if (rm == FE_UPWARD || (rm == FE_TONEAREST && (hx >=
       85 +                    0x3fe00000 && ((hx & 0xfffff) | xx.i[LOWORD]))))
  81   86                          xx.i[HIWORD] = sx | 0x3ff00000;
  82   87                  else
  83   88                          xx.i[HIWORD] = sx;
       89 +
  84   90                  xx.i[LOWORD] = 0;
  85   91                  return (xx.d);
  86   92          }
  87   93  
  88   94          /* round x at the integer bit */
  89   95          j = 0x433 - (hx >> 20);
       96 +
  90   97          if (j >= 32) {
  91   98                  i = 1 << (j - 32);
  92      -                frac = ((xx.i[HIWORD] << 1) << (63 - j)) |
  93      -                        (xx.i[LOWORD] >> (j - 32));
       99 +                frac = ((xx.i[HIWORD] << 1) << (63 - j)) | (xx.i[LOWORD] >> (j -
      100 +                    32));
      101 +
  94  102                  if (xx.i[LOWORD] & (i - 1))
  95  103                          frac |= 1;
      104 +
  96  105                  if (!frac)
  97  106                          return (x);
      107 +
  98  108                  xx.i[LOWORD] = 0;
  99  109                  xx.i[HIWORD] &= ~(i - 1);
 100      -                if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) &&
 101      -                        ((frac > 0x80000000u) || ((frac == 0x80000000) &&
 102      -                        (xx.i[HIWORD] & i)))))
      110 +
      111 +                if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) && ((frac >
      112 +                    0x80000000u) || ((frac == 0x80000000) && (xx.i[HIWORD] &
      113 +                    i)))))
 103  114                          xx.i[HIWORD] += i;
 104  115          } else {
 105  116                  i = 1 << j;
 106  117                  frac = (xx.i[LOWORD] << 1) << (31 - j);
      118 +
 107  119                  if (!frac)
 108  120                          return (x);
      121 +
 109  122                  xx.i[LOWORD] &= ~(i - 1);
 110      -                if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) &&
 111      -                        (frac > 0x80000000u || ((frac == 0x80000000) &&
 112      -                        (xx.i[LOWORD] & i))))) {
      123 +
      124 +                if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) && (frac >
      125 +                    0x80000000u || ((frac == 0x80000000) && (xx.i[LOWORD] &
      126 +                    i))))) {
 113  127                          xx.i[LOWORD] += i;
      128 +
 114  129                          if (xx.i[LOWORD] == 0)
 115  130                                  xx.i[HIWORD]++;
 116  131                  }
 117  132          }
      133 +
 118  134          return (xx.d);
 119  135  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX