/// <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 static void CheckParseError(string str) { bool foundParseError = false; try { DD.Parse(str); } catch (FormatException ex) { foundParseError = true; } Assert.IsTrue(foundParseError); }
private static void CheckParse(String str, DD expectedVal, double relErrBound) { DD xdd = DD.Parse(str); double err = xdd.Subtract(expectedVal).ToDoubleValue(); double relErr = err / xdd.ToDoubleValue(); Console.WriteLine("Parsed= " + xdd + " rel err= " + relErr); Assert.IsTrue(err <= relErrBound); }
private static void CheckParse(string str, DD expectedVal, double relErrBound) { var xdd = DD.Parse(str); double err = (xdd - expectedVal).ToDoubleValue(); double relErr = err / xdd.ToDoubleValue(); // System.Console.WriteLine(("Parsed= " + xdd + " rel err= " + relErr); Assert.IsTrue(err <= relErrBound, string.Format(NumberFormatInfo.InvariantInfo, "Parsing '" + str + "' results in " + xdd.ToString() + " ( " + xdd.Dump() + ") != " + expectedVal + "\n err =" + err + ", relerr =" + relErr)); }
/// <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) { var xdd = DD.ValueOf(x); var xSqrt = xdd.Sqrt(); string s = xSqrt.ToString(); // System.Console.WriteLine(s); var xSqrt2 = DD.Parse(s); var xx = xSqrt2 * xSqrt2; string xxStr = xx.ToString(); // System.Console.WriteLine("==> " + xxStr); var xx2 = DD.Parse(xxStr); double err = Math.Abs(xx2.ToDoubleValue() - x); Assert.IsTrue(err < 1e-10); }
/// <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); }
/// <summary> /// This routine simply tests for robustness of the toString function. /// </summary> static void WriteRepeatedSqr(DD xdd) { if (xdd.GreaterOrEqualThan(DD.ValueOf(1))) { throw new ArgumentException("Argument must be < 1"); } int count = 0; while (xdd.ToDoubleValue() > 1e-300) { count++; double x = xdd.ToDoubleValue(); var xSqr = xdd.Sqr(); string s = xSqr.ToString(); // System.Console.WriteLine(count + ": " + s); var xSqr2 = DD.Parse(s); xdd = xSqr; } }