public void NonOverlapping_Are_NonOverlapping() { var d1 = DoubleConverter.FromFloatingPointBinaryString("1100"); var d2 = DoubleConverter.FromFloatingPointBinaryString("-10.1"); Assert.IsTrue(ExpansionExtensions.AreNonOverlapping(d1, d2)); }
public void Overlapping_AreNot_NonOverlapping() { var d1 = DoubleConverter.FromFloatingPointBinaryString("101"); var d2 = DoubleConverter.FromFloatingPointBinaryString("10"); Assert.IsFalse(ExpansionExtensions.AreNonOverlapping(d1, d2)); }
public void BitWidth_Large() { double d = DoubleConverter.FromFloatingPointBinaryString("1010101" + '0'.Repeat(200)); int width = d.BitWidth(); Assert.AreEqual(7, width); }
public void BitWidth_Simple() { double d = DoubleConverter.FromFloatingPointBinaryString("-0.001010101000"); int width = d.BitWidth(); Assert.AreEqual(7, width); }
public void OptimTest() { // 53 ones string a_s = "11111111111111111111111111111111111111111111111111110.0"; double a = DoubleConverter.FromFloatingPointBinaryString("11111111111111111111111111111111111111111111111111110.0"); double b = DoubleConverter.FromFloatingPointBinaryString("-11111111111111111111111111111111111111111111111111110.0"); double c = DoubleConverter.FromFloatingPointBinaryString("00000000000000000000000000000000000000000000000000000.01"); string a_s2 = DoubleConverter.ToFloatingPointBinaryString(9.0071992547409900e+0015); Assert.AreEqual(a_s, a_s2); bool ok = Test(a, b, c); Assert.IsTrue(ok); double acc = TestAcc(a, b, c); double acc2 = TestAcc(a, b, c); if (acc != acc2) { Assert.Fail(); } Assert.AreEqual(0.0, acc); Assert.AreEqual(0.0, acc2); double tst2 = Test2(a, b, c); if (tst2 != 0.0) { Assert.Fail(); } }
public void StronglyNonOverlapping() { // Two examples that are strongly nonoverlapping (S.p12) var sn1 = new[] { DoubleConverter.FromFloatingPointBinaryString("11000"), DoubleConverter.FromFloatingPointBinaryString("11") }; var sn2 = new[] { DoubleConverter.FromFloatingPointBinaryString("10000"), DoubleConverter.FromFloatingPointBinaryString("1000"), DoubleConverter.FromFloatingPointBinaryString("10"), DoubleConverter.FromFloatingPointBinaryString("1") }; Assert.IsTrue(sn1.IsStronglyNonOverlapping()); Assert.IsTrue(sn2.IsStronglyNonOverlapping()); // Two examples that are _not_ strongly nonoverlapping (S.p12) var nsn1 = new[] { DoubleConverter.FromFloatingPointBinaryString("11100"), DoubleConverter.FromFloatingPointBinaryString("11") }; var nsn2 = new[] { DoubleConverter.FromFloatingPointBinaryString("100"), DoubleConverter.FromFloatingPointBinaryString("10"), DoubleConverter.FromFloatingPointBinaryString("1") }; Assert.IsFalse(nsn1.IsStronglyNonOverlapping()); Assert.IsFalse(nsn2.IsStronglyNonOverlapping()); }
private double?ConvertToObjectItem(string csvItem) { var c = new DoubleConverter(); Assert.IsTrue(c.TryConvertToObjectItem(CreateConvertToObjectItemContext(csvItem), out object?result, out string _)); return((double?)result); }
public void Convert_SanityCheck() { var py = Python.Instance(); var pyFloat = py.Eval("123.456789"); var converter = new DoubleConverter(); Assert.AreEqual(123.456789, converter.Convert(pyFloat)); }
private static string doubleArrayToString(double[] array, int num) { StringBuilder stringBuilder = new StringBuilder().append(array.Length); int num2 = array.Length; for (int i = 0; i < num2; i++) { double num3 = array[i]; if (num == 3) { stringBuilder.append(' ').append(DataUtil.formatDouble(num3, 10, 5)); } else if (num == 1) { DoubleConverter doubleConverter = new DoubleConverter(); long num4 = DoubleConverter.ToLong(num3, ref doubleConverter); stringBuilder.append(" 0x").append(Long.toHexString(num4)); } else if (num == 2) { stringBuilder.append(' ').append(Utilities.doubleToScientificString(num3, 8)); } } return(stringBuilder.toString()); }
static Converter() { BoolConverter.Initialize(); CharConverter.Initialize(); ByteConverter.Initialize(); SByteConverter.Initialize(); Int16Converter.Initialize(); UInt16Converter.Initialize(); Int32Converter.Initialize(); UInt32Converter.Initialize(); Int64Converter.Initialize(); UInt64Converter.Initialize(); SingleConverter.Initialize(); DoubleConverter.Initialize(); DecimalConverter.Initialize(); BigIntegerConverter.Initialize(); BytesConverter.Initialize(); CharsConverter.Initialize(); StringConverter.Initialize(); StringBuilderConverter.Initialize(); DateTimeConverter.Initialize(); TimeSpanConverter.Initialize(); GuidConverter.Initialize(); MemoryStreamConverter.Initialize(); StreamConverter.Initialize(); }
private static void DoPerformancesTest(int times) { const double d = 123456789; var w = Stopwatch.StartNew(); for (int i = 0; i < times; i++) { string s = DoubleConverter.ToExactString(d + i); Assert.IsNotNull(s); } w.Stop(); var usingDc = w.Elapsed; PrecisionModel precisionModel = new PrecisionModel(1E9); var formatter = CreateFormatter(precisionModel); string format = "0." + StringOfChar('#', formatter.NumberDecimalDigits); w = Stopwatch.StartNew(); for (int i = 0; i < times; i++) { string s = d.ToString(format, formatter); Assert.IsNotNull(s); } w.Stop(); var usingDef = w.Elapsed; if (usingDc <= usingDef) { return; } var diff = usingDc - usingDef; Console.WriteLine("slower for {0}: {1} seconds", times, diff.TotalSeconds); }
public void ShowDoubleRounding() { double a = DoubleConverter.FromFloatingPointBinaryString('1'.Repeat(52) + "0"); // 111....11110 double b = DoubleConverter.FromFloatingPointBinaryString("0.100000000001"); // 000....00000.100000000001 double expected53 = DoubleConverter.FromFloatingPointBinaryString('1'.Repeat(52) + "1"); // 111....11111 double expected64 = a; // Set Fpu to 53-bit precision (the default) FpuControl.SetState((uint)FpuControl.PrecisionControl.Double53Bits, FpuControl.Mask.PrecisionControl); double result53 = a + b; Assert.AreEqual(expected53, result53); // Set Fpu to 64-bit precision (extended precision) FpuControl.SetState((uint)FpuControl.PrecisionControl.Extended64Bits, FpuControl.Mask.PrecisionControl); double result64 = (double)(a + b); Assert.AreEqual(expected64, result64); double result64_0 = (a + b) - a; Assert.AreNotEqual(0.0, result64_0); Assert.AreNotEqual(b, result64_0); Assert.AreEqual(0.5, result64_0); // 000....00000.1 }
public void ShowDoubleRoundingPriest() { double a = Math.Pow(2.0, 52.0) + 1.0; double b = 0.5 - Math.Pow(2.0, -54.0); double expected53 = a; double expected64 = a + 1.0; // Math.Pow(2.0, 52.0) + 2.0; Debug.Print(DoubleConverter.ToFloatingPointBinaryString(a)); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(b)); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(expected53)); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(expected64)); // Set Fpu to 53-bit precision (the default) FpuControl.SetState((uint)FpuControl.PrecisionControl.Double53Bits, FpuControl.Mask.PrecisionControl); double result53 = a + b; Debug.Print(DoubleConverter.ToFloatingPointBinaryString(result53)); Assert.AreEqual(expected53, result53); // Set Fpu to 64-bit precision (extended precision) FpuControl.SetState((uint)FpuControl.PrecisionControl.Extended64Bits, FpuControl.Mask.PrecisionControl); double result64 = (double)(a + b); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(result64)); Assert.AreEqual(expected64, result64); }
public void ShowDoubleRoundingPriestExplicit() { double a = DoubleConverter.FromFloatingPointBinaryString("1" + '0'.Repeat(51) + "1"); // 100....00001 (53-bits wide) double b = DoubleConverter.FromFloatingPointBinaryString("0.0" + '1'.Repeat(53)); // 0.0111...111 (53 1's) double expected53 = a; double expected64 = a + 1.0; // The point is that this is different to expceted53. Debug.Print(DoubleConverter.ToFloatingPointBinaryString(a)); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(b)); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(expected53)); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(expected64)); // Set Fpu to 53-bit precision (the default) FpuControl.SetState((uint)FpuControl.PrecisionControl.Double53Bits, FpuControl.Mask.PrecisionControl); double result53 = a + b; Debug.Print(DoubleConverter.ToFloatingPointBinaryString(result53)); Assert.AreEqual(expected53, result53); // Explicit rounding makes no difference here (since we're in Double53bits precision FPU mode) result53 = (double)(a + b); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(result53)); Assert.AreEqual(expected53, result53); // Set Fpu to 64-bit precision (extended precision) FpuControl.SetState((uint)FpuControl.PrecisionControl.Extended64Bits, FpuControl.Mask.PrecisionControl); double result64 = (double)(a + b); Debug.Print(DoubleConverter.ToFloatingPointBinaryString(result64)); Assert.AreEqual(expected64, result64); }
public void ConvertToCsvItemTest() { var c = new DoubleConverter(); Assert.AreEqual("1000", c.ConvertToCsvItem(CreateConvertToCsvItemContext(1000d))); Assert.AreEqual("1,000", c.ConvertToCsvItem(CreateConvertToCsvItemContext(1000d, "FormattedValue"))); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Tests network. </summary> /// /// <returns> A NNManager. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public NNManager TestNetwork() { Console.WriteLine("\tTesting Network", Color.Yellow); PrintNewLine(); while (true) { PrintUnderline(50); var values = GetInputData($"\tType {_numInputParameters} inputs: "); if (values == null) { PrintNewLine(); return(this); } var results = _network?.Compute(values); PrintNewLine(); foreach (var result in results) { Console.WriteLine("\tOutput: " + DoubleConverter.ToExactString(result), Color.Aqua); } PrintNewLine(); return(this); } }
public void DoubleConverter(object input, double?expected) { var converter = new DoubleConverter(); var result = converter.Convert(input); Assert.AreEqual(expected, result); }
public void PropertiesTest() { var converter = new DoubleConverter(); Assert.AreEqual(true, converter.AcceptsNativeType); Assert.AreEqual(typeof(double), converter.ConvertedType); }
public void DoubleConverterFromDecimal() { var converter = new DoubleConverter(); var result = converter.Convert(4m / 5m); Assert.AreEqual(System.Convert.ToDouble(4m / 5m), result); }
/// <summary> /// Convert a field to a string /// </summary> /// <param name="o">object we want to convert</param> /// <returns>string representation of the string</returns> internal string ValueToString(object o) { if (mDecimalConv == null) { mDecimalConv = new DecimalConverter(DecimalSeparator); mDoubleConv = new DoubleConverter(DecimalSeparator); mSingleConv = new SingleConverter(DecimalSeparator); mDateConv = new DateTimeConverter(DateFormat); } if (o == null) { return(string.Empty); } else if (o is DateTime) { return(mDateConv.FieldToString(o)); } else if (o is decimal) { return(mDecimalConv.FieldToString(o)); } else if (o is double) { return(mDoubleConv.FieldToString(o)); } else if (o is float) { return(mSingleConv.FieldToString(o)); } else { return(o.ToString()); } }
public void TestUpdateDouble() { double value = RandomDouble.UpdateDouble(0, 5); Assert.True(value <= 5 && value >= -5); Assert.True(value == DoubleConverter.ToDouble(value)); }
public static int SumOfPower(long num, long power) { double result = (double)Math.Pow(num, power); string bigNumber = DoubleConverter.ToExactString(result); return(SumOfDigits(bigNumber)); }
private double EvalG15(string formula) { var result = Eval(formula); output.WriteLine("{0}\n{1}", formula, DoubleConverter.ToExactString((double)result)); return(Convert.ToDouble(((double)result).ToString("G15"))); }
public static void DumpFloat(int value, StringBuilder sb) { var floatValue = ToFloat(value); if (float.IsNaN(floatValue)) { return; } string shaderCode = string.Format(@" float4 main(): sv_target {{ return asfloat({0}); }}" , value); var compiledShader = ShaderBytecode.Compile(shaderCode, "main", "ps_5_0"); var shaderBytecode = compiledShader.Bytecode; var disassembly = shaderBytecode.Disassemble(); var bytecode = BytecodeContainer.Parse(shaderBytecode); var number = bytecode.Shader.InstructionTokens.First().Operands[1].ImmediateValues; StringAssert.Contains("Generated by Microsoft (R) HLSL Shader Compiler 10.1", disassembly); var expectedFloat = Regex.Match(disassembly, @"l\((.*?),").Groups[1].Value; var actualFloat = FormatFloat(floatValue); var fullFloat = DoubleConverter.ToExactString(floatValue, -1); var correct = expectedFloat == actualFloat; if (value != number.Int0) { return; } sb.AppendLine(string.Format("{0}\t{1, 50}\t{2, 50}\t{3}\t{4}", correct, expectedFloat, actualFloat, fullFloat, value)); }
public void Convert_ThrowsException_WhenNotDouble() { var py = Python.Instance(); var pyStr = py.Eval("\"omershelef\""); var converter = new DoubleConverter(); Assert.Throws<ConversionException>(() => converter.Convert(pyStr)); }
public void TryConvertToObjectItemRequireTest() { var c = new DoubleConverter(); var context = CreateConvertToObjectItemContext(string.Empty); Assert.IsFalse(c.TryConvertToObjectItem(context, out object?_, out string message)); Assert.AreEqual(CsvConfig.Current.ValidationMessage.GetRequiredError(context), message); }
public void RoundTripMinValueTest() { var converter = new DoubleConverter(); var s = converter.ConvertToString(double.MinValue, null, new MemberMapData(null)); var d = converter.ConvertFromString(s, null, new MemberMapData(null)); Assert.AreEqual(double.MinValue, d); }
public void TryConvertToObjectItemFailureTest() { var c = new DoubleConverter(); var context = CreateConvertToObjectItemContext("x"); Assert.IsFalse(c.TryConvertToObjectItem(context, out object?_, out string message)); Assert.AreEqual(CsvConfig.Current.ValidationMessage.GetNumericConvertError(context), message); }
public void ConvertTest() { DoubleConverter converter = new DoubleConverter(); var value = converter.Convert(10.25, typeof(object), null, CultureInfo.CurrentCulture); double d = 10.25; Assert.AreEqual(d, value); }
public static dynamic GetTSObject(DoubleConverter dynObject) { if (dynObject is null) { return(null); } return(dynObject.teklaObject); }
public void Split_Simple() { double d = DoubleConverter.FromFloatingPointBinaryString("-0.001010101000"); double ahi; double alo; Split_Checked(d, out ahi, out alo); }
public void small_doubles_are_formatted_properly_using_doubleconverter() { const string expected = "123456"; const double d = 123456; string actual = DoubleConverter.ToExactString(d); Assert.That(actual, Is.EqualTo(expected)); }
public void CanSerializeAndDeserialize() { double value = double.MaxValue; DoubleConverter converter = new DoubleConverter(); byte[] bytes = converter.Serialize(value); double valueFromBytes = converter.Deserialize(bytes); Assert.Equal(valueFromBytes, value); }
public void TestConvert() { var item = new TestItem() { Dvalue = -1 }; var conv = new DoubleConverter<TestItem>("Dvalue", "{0:0.0000}"); conv.SetProperty(item, "100.5"); Assert.AreEqual(100.5, item.Dvalue); Assert.AreEqual("100.5000", conv.GetProperty(item)); }
public void ShouldFailToConvertToCSharpValue() { //Arrange object value0; object value1; object value2; var converter = new DoubleConverter(); //Act bool success0 = converter.TryConvertToCSharpValue("9E10D", out value0); bool success1 = converter.TryConvertToCSharpValue("N/A", out value1); bool success2 = converter.TryConvertToCSharpValue("10000E", out value2); //Assert Assert.IsFalse(success0); Assert.IsFalse(success1); Assert.IsFalse(success2); }
public void ShouldConvertToCellValue() { //Arrange string value0; string value1; string value2; var converter = new DoubleConverter(); //Act bool success0 = converter.TryConvertToCellValue(0.123D, out value0); bool success1 = converter.TryConvertToCellValue(1000000000D, out value1); bool success2 = converter.TryConvertToCellValue(-12.84848715D, out value2); //Assert Assert.IsTrue(success0); Assert.IsTrue(success1); Assert.IsTrue(success2); Assert.AreEqual("0.123", value0); Assert.AreEqual("1000000000", value1); Assert.AreEqual("-12.84848715", value2); }
public void ShouldConvertToCSharpValue() { //Arrange object value0; object value1; object value2; var converter = new DoubleConverter(); //Act bool success0 = converter.TryConvertToCSharpValue("0.123", out value0); bool success1 = converter.TryConvertToCSharpValue("9E10", out value1); bool success2 = converter.TryConvertToCSharpValue("-12.84848715", out value2); //Assert Assert.IsTrue(success0); Assert.IsTrue(success1); Assert.IsTrue(success2); Assert.AreEqual(0.123, value0); Assert.AreEqual(9E10, value1); Assert.AreEqual(-12.84848715, value2); }
public void ShouldFailToConvertToCellValue() { //Arrange string value0; string value1; string value2; var converter = new DoubleConverter(); //Act bool success0 = converter.TryConvertToCellValue(0.18f, out value0); bool success1 = converter.TryConvertToCellValue("-1", out value1); bool success2 = converter.TryConvertToCellValue("NaN", out value2); //Assert Assert.IsFalse(success0); Assert.IsFalse(success1); Assert.IsFalse(success2); }