public static QuadDouble Pow(QuadDouble a, int n) { if (n == 0) { return(1.0); } bool negative = n < 0; n = System.Math.Abs(n); //Find largest power of 2 < b int pow = 1; for (int i = 1; i < n; i *= 2) { pow = i; } QuadDouble result = 1.0; for (int i = pow; i >= 1; i /= 2) { result = result * result; if (n >= i) { n -= i; result = result * a; } } return(negative ? 1 / result : result); }
public static QuadDouble Root(QuadDouble a, int n) { QuadDouble x0 = System.Math.Pow(a.x0, -1.0 / n); x0 += x0 * (1 - a * Pow(x0, n)) * (1.0 / n); x0 += x0 * (1 - a * Pow(x0, n)) * (1.0 / n); x0 += x0 * (1 - a * Pow(x0, n)) * (1.0 / n); return(1 / x0); }
public static QuadDouble operator/(QuadDouble a, QuadDouble b) { double q0 = a.x0 / b.x0; QuadDouble r0 = a - (q0 * b); double q1 = r0.x0 / b.x0; QuadDouble r1 = r0 - (q1 * b); double q2 = r1.x0 / b.x0; QuadDouble r2 = r1 - (q2 * b); double q3 = r2.x0 / b.x0; QuadDouble r3 = r2 - (q3 * b); double q4 = r3.x0 / b.x0; return(Renormalise(q0, q1, q2, q3, q4)); }