diff --git a/TextImprecision.sln b/TextImprecision.sln new file mode 100644 index 0000000..4827952 --- /dev/null +++ b/TextImprecision.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31112.23 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextImprecision", "TextImprecision\TextImprecision.csproj", "{A6C97958-A9E4-41E6-BF71-8BFC4784122E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A6C97958-A9E4-41E6-BF71-8BFC4784122E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6C97958-A9E4-41E6-BF71-8BFC4784122E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6C97958-A9E4-41E6-BF71-8BFC4784122E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6C97958-A9E4-41E6-BF71-8BFC4784122E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BEF755E6-4CA6-4E28-9562-1342C466B895} + EndGlobalSection +EndGlobal diff --git a/TextImprecision/Program.cs b/TextImprecision/Program.cs new file mode 100644 index 0000000..0b5c7e8 --- /dev/null +++ b/TextImprecision/Program.cs @@ -0,0 +1,118 @@ +using System; +using System.IO; + +namespace TextImprecision +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Enter the first file path: "); + string p1 = Console.ReadLine(); + Console.WriteLine("Enter the second file path: "); + string p2 = Console.ReadLine(); + + TextWriter output = File.CreateText("Imprecision.txt"); + + TextReader tr1 = File.OpenText(p1.Trim('\"')); + TextReader tr2 = File.OpenText(p2.Trim('\"')); + + output.WriteLine("Differences between {0} and {1}:", p1, p2); + bool exit = false; +#nullable enable + while (!exit) + { + string? nl1 = tr1.ReadLine(); + string? nl2 = tr2.ReadLine(); + if (nl1 == null || nl2 == null) + { + exit = true; + } + else + { + // Clear leading/trailing whitespace + nl1 = nl1.Trim(); + nl2 = nl2.Trim(); + // Get the numbers by themselves + string strDbl1 = nl1[..nl1.IndexOf(' ')]; + string strDbl2 = nl1[nl1.IndexOf(' ')..].Trim(); + string strDbl3 = nl2[..nl2.IndexOf(' ')]; + string strDbl4 = nl2[nl2.IndexOf(' ')..].Trim(); + // + int nonMatchIndex1 = -1; + int decimalPos1 = -1; + + int nonMatchIndex2 = -1; + int decimalPos2 = -1; + + for (int i = 0; i < Math.Max(strDbl1.Length, strDbl3.Length); i++) + { + if (strDbl1[i < strDbl1.Length ? i : strDbl1.Length - 1] == '.' || + strDbl3[i < strDbl3.Length ? i : strDbl3.Length - 1] == '.') + { + decimalPos1 = i; + } + if (strDbl1[i < strDbl1.Length ? i : strDbl1.Length-1] != strDbl3[i < strDbl3.Length ? i : strDbl3.Length - 1]) + { + nonMatchIndex1 = i; + break; + } + } + + for (int i = 0; i < Math.Max(strDbl2.Length, strDbl4.Length); i++) + { + if (strDbl2[i < strDbl2.Length ? i : strDbl2.Length - 1] == '.' || + strDbl4[i < strDbl4.Length ? i : strDbl4.Length - 1] == '.') + { + decimalPos2 = i; + } + if (strDbl2[i < strDbl2.Length ? i : strDbl2.Length - 1] != strDbl4[i < strDbl4.Length ? i : strDbl4.Length - 1]) + { + nonMatchIndex2 = i; + break; + } + } + + + if (nonMatchIndex1 > -1) + { + if (decimalPos1 > -1) + { + output.Write("{0} dp", nonMatchIndex1 - decimalPos1, strDbl1.Length < strDbl3.Length ? strDbl1.Length : strDbl3.Length); + } + else + { + output.Write("{0} sf", nonMatchIndex1); + } + + } + else + { + output.Write("match"); + } + output.Write("\t"); + if (nonMatchIndex2 > -1) + { + if (decimalPos2 > -1) + { + output.Write("{0} dp", nonMatchIndex2 - decimalPos2, strDbl2.Length < strDbl4.Length ? strDbl2.Length : strDbl4.Length); + } + else + { + output.Write("{0} sf", nonMatchIndex2); + } + + } + else + { + output.Write("match"); + } + output.WriteLine("\t({0:#.000000}\t{1:#.000000})", Math.Abs(Convert.ToDouble(strDbl1)-Convert.ToDouble(strDbl3)), Math.Abs(Convert.ToDouble(strDbl2) - Convert.ToDouble(strDbl4))); + + + } + } + output.Close(); + } + } +} diff --git a/TextImprecision/TextImprecision.csproj b/TextImprecision/TextImprecision.csproj new file mode 100644 index 0000000..2082704 --- /dev/null +++ b/TextImprecision/TextImprecision.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + +