All Projects → miroiu → string-math

miroiu / string-math

Licence: MIT license
Evaluates a math expression from a string. Supports variables and custom operators.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to string-math

String Calc
PHP calculator library for mathematical terms (expressions) passed as strings
Stars: ✭ 60 (+328.57%)
Mutual labels:  calculator, math, string, mathematics
Computator.net
Computator.NET is a special kind of numerical software that is fast and easy to use but not worse than others feature-wise. It's features include: - Real and complex functions charts - Real and complex calculator - Real functions numerical calculations including different methods - Over 107 Elementary functions - Over 141 Special functions - Over 21 Matrix functions and operations - Scripting language with power to easy computations including matrices - You can declare your own custom functions with scripting language
Stars: ✭ 174 (+1142.86%)
Mutual labels:  calculator, math, mathematics
rclc
Mathematical expression calculator with big integers, floats, common fractions, and complex numbers support
Stars: ✭ 24 (+71.43%)
Mutual labels:  calculator, math, mathematics
java.math.expression.parser
java math expression parser is faster than JEP
Stars: ✭ 25 (+78.57%)
Mutual labels:  math, expression-parser, expression-evaluator
pratt-calculator
A very simple expression evaluator written using a Pratt Parser
Stars: ✭ 22 (+57.14%)
Mutual labels:  calculator, expression-parser, expression-evaluator
Calc
C-style arbitrary precision calculator
Stars: ✭ 127 (+807.14%)
Mutual labels:  calculator, math, mathematics
MathImprove
Modify and Improve math expressions.
Stars: ✭ 13 (-7.14%)
Mutual labels:  math, mathematics, math-expression
Fourier-and-Images
Fourier and Images
Stars: ✭ 81 (+478.57%)
Mutual labels:  math, mathematics
Linear-Algebra-and-Its-Applications-notes
《线性代数及其应用》笔记
Stars: ✭ 196 (+1300%)
Mutual labels:  math, mathematics
graphest
A faithful graphing calculator
Stars: ✭ 42 (+200%)
Mutual labels:  math, mathematics
Mathematics for Machine Learning
Learn mathematics behind machine learning and explore different mathematics in machine learning.
Stars: ✭ 28 (+100%)
Mutual labels:  math, mathematics
noteworthy
Markdown editor with bidirectional links and excellent math support, powered by ProseMirror. (In Development!)
Stars: ✭ 178 (+1171.43%)
Mutual labels:  math, mathematics
mml-book-chinese
mml-book-chinese《Mathematics For Machine Learning》机器学习中的数学 中文版
Stars: ✭ 113 (+707.14%)
Mutual labels:  math, mathematics
Tau.jl
A Julia module providing the definition of the circle constant Tau (2π)
Stars: ✭ 33 (+135.71%)
Mutual labels:  math, mathematics
Mathos-Project
The Mathos Core Library
Stars: ✭ 22 (+57.14%)
Mutual labels:  math, mathematics
Oscar.jl
A comprehensive open source computer algebra system for computations in algebra, geometry, and number theory.
Stars: ✭ 182 (+1200%)
Mutual labels:  math, mathematics
speedy-math
An application which allows user (small kids) to practice basic Mathematics operations
Stars: ✭ 28 (+100%)
Mutual labels:  math, mathematics
codex
A repository of mathematical knowledge written in the MathLingua language.
Stars: ✭ 17 (+21.43%)
Mutual labels:  math, mathematics
Mather
A powerful expression-based calculator, unit converter, and general computation engine for Android
Stars: ✭ 49 (+250%)
Mutual labels:  calculator, math
textics
📉 JavaScript Text Statistics that counts lines, words, chars, and spaces.
Stars: ✭ 36 (+157.14%)
Mutual labels:  string, string-calculator

String Math NuGet Downloads .NET

Calculates the value of a math expression from a string returning a double. Supports variables and user defined operators.

Creating and using a calculator

ICalculator myCalculator = new Calculator();
double result = myCalculator.Evaluate("1 * (2 - 3) ^ 2"); // 1

// Using custom operators
myCalculator.AddOperator("abs", a => a > 0 ? a : -a);
double result = myCalculator.Evaluate("abs -5"); // 5

// Using custom operator precedence (you can specify an int for precedence)
myCalculator.AddOperator("max", (a, b) => a > b ? a : b, Precedence.Power);
double result = myCalculator.Evaluate("2 * 3 max 4"); // 8

Creating and using variables

// Default variables collection is optional
ICalculator myCalculator = new Calculator(new VariablesCollection
{
	["a"] = 5,
	["PI"] = 3.1415926535897931
});

// Setting or creating variables
myCalculator.SetValue("a", 2);
myCalculator["b"] = 1;

double result = myCalculator.Evaluate("{a} + 2 * {b} + {PI}"); // 7.1415926535897931

Creating and reusing operations

myCalculator.SetValue("a", 5);

// Creating operations (expression tree is optimized and cached)
OperationInfo op = myCalculator.CreateOperation("2 * {a}");
double result1 = myCalculator.Evaluate(op); // 10

myCalculator["a"] = 3;
// Reusing the operation (improved performance)
double result2 = myCalculator.Evaluate(op); // 6

Using the static api: SMath

// Same API as a calculator instance
double result = SMath.Evaluate("1 + 1"); // 2
SMath.SetValue("myVar", 1);
double result = SMath.Evaluate("1 + {myVar}", ); // 2

Default binary operators

+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (remainder)
^ (power)
log (logarithm)
max (maximum)
min (minimum)

Default unary operators

- (negation)
! (factorial)
sqrt (square root)
sin (sinus)
cos (cosinus)
tan (tangent)
ceil (ceiling)
floor (floor)
round (rounding)
exp (e raised to power)
abs (absolute)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].