Skip to content

Commit

Permalink
Fixed BMath.Add
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoMaturino1 authored May 20, 2023
1 parent 2c8a01f commit a775ea3
Show file tree
Hide file tree
Showing 40 changed files with 498 additions and 0 deletions.
41 changes: 41 additions & 0 deletions BrennCode/BrennCode.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32516.85
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrennCode", "BrennCode\BrennCode.csproj", "{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}.Debug|x64.ActiveCfg = Debug|x64
{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}.Debug|x64.Build.0 = Debug|x64
{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}.Release|Any CPU.Build.0 = Release|Any CPU
{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}.Release|x64.ActiveCfg = Release|x64
{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}.Release|x64.Build.0 = Release|x64
{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}.Debug|x64.ActiveCfg = Debug|Any CPU
{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}.Debug|x64.Build.0 = Debug|Any CPU
{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}.Release|Any CPU.Build.0 = Release|Any CPU
{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}.Release|x64.ActiveCfg = Release|Any CPU
{EA26CF40-DF2F-4836-AC8C-BA83C6E39752}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1071825F-22DA-422A-A2EC-401B5FD7544A}
EndGlobalSection
EndGlobal
82 changes: 82 additions & 0 deletions BrennCode/BrennCode/BMath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace BrennCode
{
public class BMath
{
/// <summary>
/// Add 2 string numbers
/// <br/> If you put something like a point or a letter (Anything it will give you the wrong result)
/// </summary>
/// <param name="n1">First number to add</param>
/// <param name="n2">Second number to add</param>
/// <returns>Returns string</returns>
public static string Add(string n1, string n2)
{
/*if (!n1.Any(x => char.IsLetter(x) || !char.IsPunctuation(x)) || !n2.Any(x => char.IsLetter(x) || !char.IsPunctuation(x)))
return "0";*/



if (n1.Any(x => char.IsPunctuation(x)) || n2.Any(x => char.IsPunctuation(x)))
{
string[] n1Split = n1.Split('.');
string[] n2Split = n2.Split('.');
int carry = 0;
string add1 = rawAdd(n1Split[1], n2Split[1], ref carry);
string add0 = rawAdd(n1Split[0], n2Split[0], ref carry);

return carry + add0 + "." + add1;
}
return "0";

}

private static string rawAdd(string n1, string n2, ref int carry)
{
var eq = EqualNumbers(n1, n2);
n1 = eq.n1Out; n2 = eq.n2Out;
List<String> output = new List<String>();
for (int i = n1.Length; i-- > 0;)
{
int n1Int = int.Parse(n1[i].ToString());
int n2Int = int.Parse(n2[i].ToString());

int result = n1Int + n2Int + carry;
carry = result / 10;
output.Add((result % 10).ToString());
}
return String.Join("", output.ToArray());
}

private static string rawSubtract(string n1, string n2, ref int carry)
{
var eq = EqualNumbers(n1, n2);
n1 = eq.n1Out; n2 = eq.n2Out;

}

private static (string n1Out, string n2Out, int npadded) EqualNumbers(string n1, string n2)
{
if (n1.Length > n2.Length)
{
string b2 = n2.PadLeft(n1.Length, '0');
return (b2, n1, 1);
}
else if (n1.Length < n2.Length)
{
string a2 = n1.PadLeft(n2.Length, '0');
return (n1, a2, 2);
}
else
{
return (n1, n2, 0);
}
}
}
}
68 changes: 68 additions & 0 deletions BrennCode/BrennCode/BrennCode.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9E3A42D3-8BC2-4905-ACE8-5B13BB28CB1F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BrennCode</RootNamespace>
<AssemblyName>BrennCode</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ColorfulConsole.cs" />
<Compile Include="Info.cs" />
<Compile Include="BMath.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
48 changes: 48 additions & 0 deletions BrennCode/BrennCode/ColorfulConsole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace BrennCode
{
public class ColorfulConsole
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetConsoleMode(IntPtr handle, out int mode);


[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetStdHandle(int handle);

/// <summary>
/// Write a line with your RGB color (0-255), Maybe i add a HEX method soon
/// </summary>
/// <param name="text">Your text</param>
/// <param name="r">Red</param>
/// <param name="g">Green</param>
/// <param name="b">Blue</param>
public static void WriteLine(string text, int r, int g, int b)
{
var handle = GetStdHandle(-11);
int mode;
GetConsoleMode(handle, out mode);
SetConsoleMode(handle, mode | 0x4);

Console.WriteLine("\x1b[38;2;" + r + ";" + g + ";" + b + "m" + text);
}
public static void Write(string text, int r, int g, int b)
{
var handle = GetStdHandle(-11);
int mode;
GetConsoleMode(handle, out mode);
SetConsoleMode(handle, mode | 0x4);

Console.Write("\x1b[38;2;" + r + ";" + g + ";" + b + "m" + text);
}
}
}
46 changes: 46 additions & 0 deletions BrennCode/BrennCode/Info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrennCode
{
public class Info
{
/// <summary>
/// Shows in the console a message about BrennCode
/// </summary>
public static void About()
{
ConsoleColor color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;

Console.WriteLine("This program is using BrennCode!");
Console.WriteLine("BrennCode, or BC is a billboard that offers resources for console and WinForms apps");
Console.WriteLine("Resources offered:");
Console.WriteLine("MUUUCH More precise math (but slower for complex operations and support only strings)");
Console.WriteLine("RGB Write & WriteLine for Console apps");
Console.WriteLine("---DEVELOPED BY BRENNOMATURINO1---");
Console.WriteLine("GIVE ME IDEAS ON GITHUB!");
Console.WriteLine("github.com/BrennoMaturino1/BrennCode");

Console.ForegroundColor = color;
}
public static void ChangeLog()
{
ConsoleColor color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;

Console.WriteLine("- I'm finnally back to the development!");
Console.WriteLine("- BMath.Add is now working properly");
Console.WriteLine("-");
Console.WriteLine("-");
Console.WriteLine("-");
Console.WriteLine("---DEVELOPED BY BRENNOMATURINO1---");
Console.WriteLine("github.com/BrennoMaturino1/BrennCode");

Console.ForegroundColor = color;
}
}
}
36 changes: 36 additions & 0 deletions BrennCode/BrennCode/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// As informações gerais sobre um assembly são controladas por
// conjunto de atributos. Altere estes valores de atributo para modificar as informações
// associada a um assembly.
[assembly: AssemblyTitle("BrennCode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BrennCode")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Definir ComVisible como false torna os tipos neste assembly invisíveis
// para componentes COM. Caso precise acessar um tipo neste assembly de
// COM, defina o atributo ComVisible como true nesse tipo.
[assembly: ComVisible(false)]

// O GUID a seguir será destinado à ID de typelib se este projeto for exposto para COM
[assembly: Guid("9e3a42d3-8bc2-4905-ace8-5b13bb28cb1f")]

// As informações da versão de um assembly consistem nos quatro valores a seguir:
//
// Versão Principal
// Versão Secundária
// Número da Versão
// Revisão
//
// É possível especificar todos os valores ou usar como padrão os Números de Build e da Revisão
// usando o "*" como mostrado abaixo:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file added BrennCode/BrennCode/bin/Debug/BrennCode.dll
Binary file not shown.
Binary file added BrennCode/BrennCode/bin/Debug/BrennCode.pdb
Binary file not shown.
Binary file added BrennCode/BrennCode/bin/x64/Debug/BrennCode.dll
Binary file not shown.
Binary file added BrennCode/BrennCode/bin/x64/Debug/BrennCode.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
526b1c0408fb89b827bf726134a828c2d41d5f8d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
C:\Users\User 01\source\repos\BrennCode\BrennCode\bin\Debug\BrennCode.dll
C:\Users\User 01\source\repos\BrennCode\BrennCode\bin\Debug\BrennCode.pdb
C:\Users\User 01\source\repos\BrennCode\BrennCode\obj\Debug\BrennCode.csproj.AssemblyReference.cache
C:\Users\User 01\source\repos\BrennCode\BrennCode\obj\Debug\BrennCode.csproj.CoreCompileInputs.cache
C:\Users\User 01\source\repos\BrennCode\BrennCode\obj\Debug\BrennCode.dll
C:\Users\User 01\source\repos\BrennCode\BrennCode\obj\Debug\BrennCode.pdb
Binary file added BrennCode/BrennCode/obj/Debug/BrennCode.dll
Binary file not shown.
Binary file added BrennCode/BrennCode/obj/Debug/BrennCode.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cc788d70ef9d8a3db504887e269c376042c0e7fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
C:\Users\c0nta\source\repos\BrennCode\BrennCode\bin\x64\Debug\BrennCode.dll
C:\Users\c0nta\source\repos\BrennCode\BrennCode\bin\x64\Debug\BrennCode.pdb
C:\Users\c0nta\source\repos\BrennCode\BrennCode\obj\x64\Debug\BrennCode.csproj.AssemblyReference.cache
C:\Users\c0nta\source\repos\BrennCode\BrennCode\obj\x64\Debug\BrennCode.csproj.CoreCompileInputs.cache
C:\Users\c0nta\source\repos\BrennCode\BrennCode\obj\x64\Debug\BrennCode.dll
C:\Users\c0nta\source\repos\BrennCode\BrennCode\obj\x64\Debug\BrennCode.pdb
Binary file added BrennCode/BrennCode/obj/x64/Debug/BrennCode.dll
Binary file not shown.
Binary file added BrennCode/BrennCode/obj/x64/Debug/BrennCode.pdb
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions BrennCode/TestApp/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
31 changes: 31 additions & 0 deletions BrennCode/TestApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BrennCode;
namespace TestApp
{
internal class Program
{
static void Main(string[] args)
{
Info.About();
Info.ChangeLog();
ColorfulConsole.WriteLine("hello world", 50, 255, 255);
ColorfulConsole.Write("hello ", 255, 0, 0);
ColorfulConsole.Write("wor", 0, 255, 0);
ColorfulConsole.WriteLine("ld", 0, 0, 255);
Console.ForegroundColor = ConsoleColor.Green;
string add1 = "99.9";
string add2 = "99.9";
var sw = Stopwatch.StartNew();
string addRes = BMath.Add(add1, add2);
sw.Stop();
Console.WriteLine($"O resultado de {add1} + {add2} é igual a " + addRes + $". O calulo foi feito em {sw.ElapsedMilliseconds} milisegundos");
//199.8
Console.ReadLine();
}
}
}
Loading

0 comments on commit a775ea3

Please sign in to comment.