/** * Returns a new DoubleDouble whose value is <tt>-this</tt>. * * @return <tt>-this</tt> */ public final DD negate() { if (isNaN()) return this; return new DD(-hi, -lo); }
/** * Subtracts the argument from the value of <tt>this</tt>. * To prevent altering constants, * this method <b>must only</b> be used on values known to * be newly created. * * @param y the addend * @return this object, decreased by y */ public final DD selfSubtract(double y) { if (isNaN()) return this; return selfAdd(-y, 0.0); }
/** * Returns the string for this value if it has a known representation. * (E.g. NaN or 0.0) * * @return the string for this special number * or null if the number is not a special number */ private String getSpecialNumberString() { if (isZero()) return "0.0"; if (isNaN()) return "NaN "; return null; }
/** * Subtracts the argument from the value of <tt>this</tt>. * To prevent altering constants, * this method <b>must only</b> be used on values known to * be newly created. * * @param y the addend * @return this object, decreased by y */ public final DD selfSubtract(DD y) { if (isNaN()) return this; return selfAdd(-y.hi, -y.lo); }
/** * Returns the smallest (closest to negative infinity) value * that is not less than the argument and is equal to a mathematical integer. * Special cases: * <ul> * <li>If this value is NaN, returns NaN. * </ul> * * @return the smallest (closest to negative infinity) value * that is not less than the argument and is equal to a mathematical integer. */ public DD ceil() { if (isNaN()) return NaN; double fhi=Math.ceil(hi); double flo = 0.0; // Hi is already integral. Ceil the low word if (fhi == hi) { flo = Math.ceil(lo); // do we need to renormalize here? } return new DD(fhi, flo); }
/** * Returns the largest (closest to positive infinity) * value that is not greater than the argument * and is equal to a mathematical integer. * Special cases: * <ul> * <li>If this value is NaN, returns NaN. * </ul> * * @return the largest (closest to positive infinity) * value that is not greater than the argument * and is equal to a mathematical integer. */ public DD floor() { if (isNaN()) return NaN; double fhi=Math.floor(hi); double flo = 0.0; // Hi is already integral. Floor the low word if (fhi == hi) { flo = Math.floor(lo); } // do we need to renormalize here? return new DD(fhi, flo); }
/** * Rounds this value to the nearest integer. * The value is rounded to an integer by adding 1/2 and taking the floor of the result. * Special cases: * <ul> * <li>If this value is NaN, returns NaN. * </ul> * * @return this value rounded to the nearest integer */ public DD rint() { if (isNaN()) return this; // may not be 100% correct DD plus5 = this.add(0.5); return plus5.floor(); }
/** * Returns a new DoubleDouble whose value is <tt>(this * y)</tt>. * * @param y the multiplicand * @return <tt>(this * y)</tt> */ public final DD multiply(DD y) { if (y.isNaN()) return createNaN(); return copy(this).selfMultiply(y); }
/** * Returns the absolute value of this value. * Special cases: * <ul> * <li>If this value is NaN, it is returned. * </ul> * * @return the absolute value of this value */ public DD abs() { if (isNaN()) return NaN; if (isNegative()) return negate(); return new DD(this); }
/** * Returns the integer which is largest in absolute value and not further * from zero than this value. * Special cases: * <ul> * <li>If this value is NaN, returns NaN. * </ul> * * @return the integer which is largest in absolute value and not further from zero than this value */ public DD trunc() { if (isNaN()) return NaN; if (isPositive()) return floor(); else return ceil(); }