/// <summary> /// This routine simply tests for robustness of the ToString function. /// </summary> private static void WriteRepeatedSqrt(DD xdd) { int count = 0; while (xdd.ToDoubleValue() > 1e-300) { count++; // if (count == 100) // count = count; double x = xdd.ToDoubleValue(); var xSqrt = xdd.Sqrt(); string s = xSqrt.ToString(); // System.Console.WriteLine((count + ": " + s); var xSqrt2 = DD.Parse(s); var xx = xSqrt2.Multiply(xSqrt2); double err = Math.Abs(xx.ToDoubleValue() - x); // assertTrue(err < 1e-10); xdd = xSqrt; // square roots converge on 1 - stop when very close var distFrom1DD = xSqrt.Subtract(DD.ValueOf(1.0)); double distFrom1 = distFrom1DD.ToDoubleValue(); if (Math.Abs(distFrom1) < 1.0e-40) { break; } } }
private void CheckSqrt(DD x, double errBound) { DD sqrt = x.Sqrt(); DD x2 = sqrt.Multiply(sqrt); CheckErrorBound("Sqrt", x, x2, errBound); }
private void CheckSqrt(DD x, double errBound) { var sqrt = x.Sqrt(); var x2 = sqrt * sqrt; CheckErrorBound("Sqrt", x, x2, errBound); }
/// <summary> /// Tests that printing values with many decimal places works. /// This tests the correctness and robustness of both output and input. /// </summary> static void WriteAndReadSqrt(double x) { DD xdd = DD.ValueOf(x); DD xSqrt = xdd.Sqrt(); String s = xSqrt.ToString(); // System.out.println(s); DD xSqrt2 = DD.Parse(s); DD xx = xSqrt2 * xSqrt2; String xxStr = xx.ToString(); // System.out.println("==> " + xxStr); DD xx2 = DD.Parse(xxStr); double err = Math.Abs(xx2.ToDoubleValue() - x); Assert.IsTrue(err < 1e-10); }
/** * This routine simply tests for robustness of the toString function. * * @param xdd */ private static void WriteRepeatedSqrt(DD xdd) { int count = 0; while (xdd.ToDoubleValue() > 1e-300) { count++; //if (count == 100) // count = count; double x = xdd.ToDoubleValue(); DD xSqrt = xdd.Sqrt(); String s = xSqrt.ToString(); // System.out.println(count + ": " + s); DD xSqrt2 = DD.Parse(s); DD xx = xSqrt2.Multiply(xSqrt2); double err = Math.Abs(xx.ToDoubleValue() - x); //assertTrue(err < 1e-10); xdd = xSqrt; // square roots converge on 1 - stop when very close DD distFrom1DD = xSqrt.Subtract(DD.ValueOf(1.0)); double distFrom1 = distFrom1DD.ToDoubleValue(); if (Math.Abs(distFrom1) < 1.0e-40) break; } }
private void CheckSqrt(DD x, double errBound) { DD sqrt = x.Sqrt(); DD x2 = sqrt.Multiply(sqrt); CheckErrorBound("Sqrt", x, x2, errBound); }