Byces.Calculator 1.0.0

Additional Details

This package has a severe level bug, causing specific calculations to give wrong results. Update to the latest version.

There is a newer version of this package available.
See the version list below for details.
dotnet add package Byces.Calculator --version 1.0.0                
NuGet\Install-Package Byces.Calculator -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Byces.Calculator" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Byces.Calculator --version 1.0.0                
#r "nuget: Byces.Calculator, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Byces.Calculator as a Cake Addin
#addin nuget:?package=Byces.Calculator&version=1.0.0

// Install Byces.Calculator as a Cake Tool
#tool nuget:?package=Byces.Calculator&version=1.0.0                

Byces.Calculator

.NET

A simple .NET calculator that solves string math expressions

Usage example

string expression = "2 + 5 * 3";

MathResult mathResult = MathResultBuilder.GetMathResult(expression);
// or
MathResult mathResult = new MathResultBuilder().WithExpression(expression).Build();

if (mathResult.IsValid) // true
{
    Console.WriteLine(mathResult.Result); // 17
}
else
{
    Console.WriteLine(mathResult.ErrorMessage);
}

Public Models

MathResult (readonly struct)

Property Type Summary
IsValid bool Gets the validity of the MathResult instance
ErrorMessage string? Gets the error message of a possible syntax problem
ErrorType ResultErrorType Gets the expression error type
Result double Gets the expression result

MathResultBuilder (class)

Property / Method Type Summary
Expression string Gets or sets the expression of a MathResultBuilder
WithExpression(expression) MathResultBuilder Sets the expression to be builded
Build() MathResult Builds the MathResult with the given information
static GetMathResult(expression) MathResult Gets the MathResult without having to create a MathResultBuilder object

Building expressions

Before showing some syntax examples, here are some observations:

  • Numbers, operations and self operations are not case sensitive
  • The builder is not sensitive to whitespace and using it has a low impact on performance
// You can use signs to represent negative and positive numbers
string expressionExample1 = "-5 + +5";

// You can use parentheses to set priorities in the expression
string expressionExample2 = "((2 + 5) * 2) * 3";

// You can also represent numbers like this
string expressionExample3 = "1E+3";

// This is an expression with two operations and two self operations
string expressionExample4 = "fact(2 + 3) * fact3";

<hr />

Available operations

Add
string expression1 = "2+4+6";
string expression2 = "2 add 4 add 6";
Subtract
string expression1 = "2-4-6";
string expression2 = "2 sub 4 sub 6";
Multiply
string expression1 = "2*4*6";
string expression2 = "2 mul 4 mul 6";
Divide
string expression1 = "2/4/6";
string expression2 = "2 div 4 div 6";
Power
string expression1 = "2^4^6";
string expression2 = "2 pow 4 pow 6";
Root
string expression1 = "2√4√6";
string expression2 = "2 rt 4 rt 6";
Modulus
string expression1 = "2%4%6";
string expression2 = "2 mod 4 mod 6";

<hr />

Available self operations

Factorial
string expression = "fact(3)";
Square root
string expression1 = "sqrt(3)";
string expression2 = "√3";
Cube root
string expression = "cbrt(3)";
Cosine
string expression = "cos(3)";
Sine
string expression = "sin(3)";
Tangent
string expression = "tan(3)";
Cosine hyperbolic
string expression = "cosh(3)";
Sine hyperbolic
string expression = "sinh(3)";
Tangent hyperbolic
string expression = "tanh(3)";
Radian (360º)
string expression = "rad(3)";

<hr />

Available special numbers

PI
string expression1 = "π";
string expression2 = "pi";
Euler
string expression = "euler";

Feedback and Bugs

Feel free to send suggestions and problems on the Issues tab on Github, thanks to those who read this far! 😄

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.3.0 119 4/11/2024
3.2.0 134 3/18/2024
3.1.1 125 2/22/2024
3.1.0 127 2/21/2024
3.0.1 127 1/28/2024
3.0.0 167 9/16/2023
2.0.0 229 3/10/2023
1.1.4 235 2/25/2023
1.1.3 258 2/23/2023 1.1.3 is deprecated.
1.1.2 308 1/28/2023 1.1.2 is deprecated.
1.1.1 306 1/28/2023 1.1.1 is deprecated.
1.1.0 306 1/28/2023 1.1.0 is deprecated.
1.0.2 309 1/24/2023 1.0.2 is deprecated.
1.0.1 294 1/23/2023 1.0.1 is deprecated.
1.0.0 312 1/23/2023 1.0.0 is deprecated.