/** * Creates a new DoubleDouble with the value of the argument. * * @param dd the DoubleDouble value to copy * @return a copy of the input value */ public static DD copy(DD dd) { return new DD(dd); }
/** * Converts the <tt>double</tt> argument to a DoubleDouble number. * * @param x a numeric value * @return the extended precision version of the value */ public static DD valueOf(double x) { return new DD(x); }
private static DD createNaN() { return new DD(Double.NaN, Double.NaN); }
/** * Computes a new DoubleDouble whose value is <tt>(this / y)</tt>. * * @param y the divisor * @return a new object with the value <tt>(this / y)</tt> */ public final DD divide(DD y) { double hc, tc, hy, ty, C, c, U, u; C = hi/y.hi; c = SPLIT*C; hc =c-C; u = SPLIT*y.hi; hc = c-hc; tc = C-hc; hy = u-y.hi; U = C * y.hi; hy = u-hy; ty = y.hi-hy; u = (((hc*hy-U)+hc*ty)+tc*hy)+tc*ty; c = ((((hi-U)-u)+lo)-C*y.lo)/y.hi; u = C+c; double zhi = u; double zlo = (C-u)+c; return new DD(zhi, zlo); }
/** * Returns a DoubleDouble whose value is <tt>1 / this</tt>. * * @return the reciprocal of this value */ public final DD reciprocal() { double hc, tc, hy, ty, C, c, U, u; C = 1.0/hi; c = SPLIT*C; hc =c-C; u = SPLIT*hi; hc = c-hc; tc = C-hc; hy = u-hi; U = C*hi; hy = u-hy; ty = hi-hy; u = (((hc*hy-U)+hc*ty)+tc*hy)+tc*ty; c = ((((1.0-U)-u))-C*lo)/hi; double zhi = C+c; double zlo = (C-zhi)+c; return new DD(zhi, zlo); }
/** * Returns a DoubleDouble whose value is <tt>-this</tt>. * * @return <tt>-this</tt> */ public final DD negate() { if (isNaN()) return this; return new DD(-hi, -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); }
/** * 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); }
DD val = new DD();
return valueOf(1.0); DD r = new DD(this); DD s = valueOf(1.0); int n = Math.abs(exp);
public static final DD PI = new DD( 3.141592653589793116e+00, 1.224646799147353207e-16); public static final DD TWO_PI = new DD( 6.283185307179586232e+00, 2.449293598294706414e-16); public static final DD PI_2 = new DD( 1.570796326794896558e+00, 6.123233995736766036e-17); public static final DD E = new DD( 2.718281828459045091e+00, 1.445646891729250158e-16); public static final DD NaN = new DD(Double.NaN, Double.NaN);
/** * Creates a new DoubleDouble with the value of the argument. * * @param dd the DoubleDouble value to copy * @return a copy of the input value */ public static DD copy(DD dd) { return new DD(dd); }
/** * Converts the <tt>double</tt> argument to a DoubleDouble number. * * @param x a numeric value * @return the extended precision version of the value */ public static DD valueOf(double x) { return new DD(x); }
private static DD createNaN() { return new DD(Double.NaN, Double.NaN); }
/** * Computes a new DoubleDouble whose value is <tt>(this / y)</tt>. * * @param y the divisor * @return a new object with the value <tt>(this / y)</tt> */ public final DD divide(DD y) { double hc, tc, hy, ty, C, c, U, u; C = hi/y.hi; c = SPLIT*C; hc =c-C; u = SPLIT*y.hi; hc = c-hc; tc = C-hc; hy = u-y.hi; U = C * y.hi; hy = u-hy; ty = y.hi-hy; u = (((hc*hy-U)+hc*ty)+tc*hy)+tc*ty; c = ((((hi-U)-u)+lo)-C*y.lo)/y.hi; u = C+c; double zhi = u; double zlo = (C-u)+c; return new DD(zhi, zlo); }
/** * Returns a DoubleDouble whose value is <tt>1 / this</tt>. * * @return the reciprocal of this value */ public final DD reciprocal() { double hc, tc, hy, ty, C, c, U, u; C = 1.0/hi; c = SPLIT*C; hc =c-C; u = SPLIT*hi; hc = c-hc; tc = C-hc; hy = u-hi; U = C*hi; hy = u-hy; ty = hi-hy; u = (((hc*hy-U)+hc*ty)+tc*hy)+tc*ty; c = ((((1.0-U)-u))-C*lo)/hi; double zhi = C+c; double zlo = (C-zhi)+c; return new DD(zhi, zlo); }
/** * 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); }
/** * 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 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); }