private static void CheckReciprocal(double x, double errBound) { var xdd = new DD(x); var rr = xdd.Reciprocal().Reciprocal(); var err = xdd.Subtract(rr).ToDoubleValue(); Console.WriteLine("DD Recip = " + xdd + " DD delta= " + err + " double recip delta= " + (x - 1.0 / (1.0 / x))); Assert.IsTrue(err <= errBound); }
private static void CheckReciprocal(double x, double errBound) { var xdd = new DD(x); var rr = xdd.Reciprocal().Reciprocal(); double err = (xdd - rr).ToDoubleValue(); // TestContext.WriteLine("DD Recip = " + xdd // + " DD delta= " + err // + " double recip delta= " + (x - 1.0/(1.0/x))); Assert.IsTrue(err <= errBound); }
private static DD SlowPow(DD x, int exp) { if (exp == 0) { return(DD.ValueOf(1.0)); } var n = Math.Abs(exp); // MD - could use binary exponentiation for better precision & speed var pow = new DD(x); for (int i = 1; i < n; i++) { pow = pow.Multiply(x); } if (exp < 0) { return(pow.Reciprocal()); } return(pow); }
private static DD SlowPow(DD x, int exp) { if (exp == 0) return DD.ValueOf(1.0); var n = Math.Abs(exp); // MD - could use binary exponentiation for better precision & speed var pow = new DD(x); for (int i = 1; i < n; i++) { pow = pow.Multiply(x); } if (exp < 0) { return pow.Reciprocal(); } return pow; }
private static void CheckReciprocal(double x, double errBound) { var xdd = new DD(x); var rr = xdd.Reciprocal().Reciprocal(); var err = xdd.Subtract(rr).ToDoubleValue(); Console.WriteLine("DD Recip = " + xdd + " DD delta= " + err + " double recip delta= " + (x - 1.0/(1.0/x))); Assert.IsTrue(err <= errBound); }