Compare commits

..

2 Commits

Author SHA1 Message Date
dd64bbb769 Add project files. 2021-05-21 19:21:46 +12:00
d462e0f3fb Add .gitignore and .gitattributes. 2021-05-21 19:21:46 +12:00
4 changed files with 214 additions and 0 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

25
TextImprecision.sln Normal file
View File

@ -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

118
TextImprecision/Program.cs Normal file
View File

@ -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();
}
}
}

View File

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>