code: public static double ulp(double d) {
          int exp = getExponent(d);
  
          switch(exp) {
          case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
              return Math.abs(d);
  
          case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
              return Double.MIN_VALUE;
  
          default:
              assert exp <= DoubleConsts.MAX_EXPONENT && exp >= DoubleConsts.MIN_EXPONENT;
  
              // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
              exp = exp - (DoubleConsts.SIGNIFICAND_WIDTH-1);
              if (exp >= DoubleConsts.MIN_EXPONENT) {
                  return powerOfTwoD(exp);
              }
              else {
                  // return a subnormal result; left shift integer
                  // representation of Double.MIN_VALUE appropriate
                  // number of positions
                  return Double.longBitsToDouble(1L <<
                  (exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) ));
              }
          }
      }
docs: Returns the size of an ulp of the argument.  An ulp of a
  {@code double} value is the positive distance between this
  floating-point value and the {@code double} value next
  larger in magnitude.  Note that for non-NaN <i>x</i>,
  <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
  
  <p>Special Cases:
  <ul>
  <li> If the argument is NaN, then the result is NaN.
  <li> If the argument is positive or negative infinity, then the
  result is positive infinity.
  <li> If the argument is positive or negative zero, then the result is
  {@code Double.MIN_VALUE}.
  <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
  the result is equal to 2<sup>971</sup>.
  </ul>
  
  @param d the floating-point value whose ulp is to be returned
  @return the size of an ulp of the argument
  @author Joseph D. Darcy
  @since 1.5