ILMath 1.2.0

dotnet add package ILMath --version 1.2.0
NuGet\Install-Package ILMath -Version 1.2.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="ILMath" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ILMath --version 1.2.0
#r "nuget: ILMath, 1.2.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 ILMath as a Cake Addin
#addin nuget:?package=ILMath&version=1.2.0

// Install ILMath as a Cake Tool
#tool nuget:?package=ILMath&version=1.2.0

⚡ ILMath

ILMath is a hyper-fast and flexible math expression parser for C# and .NET.

Features

  • ⚡ Compiles math expressions to IL code!
  • 🔃 Compiled expressions can be reused many times!
  • 📦 Supports many math functions and constants (including custom)!
  • 🔥 Extremely fast (after compilation)!
  • 📚 Easy to use!

Installation

ILMath is available as a NuGet package.

Usage

using ILMath;

// Create a new evaluation context
var context = EvaluationContext.CreateDefault();

// Register a custom function
context.RegisterFunction("myFunction", parameters => parameters[0] + parameters[1]);

// Register a custom variable
context.RegisterVariable("myVariable", 5);

// Create a new evaluator with name "MyFunction" and expression "myFunction(2, myVariable) * 3"
var evaluator = MathEvaluation.CompileExpression("MyFunction", "myFunction(2, myVariable) * 3");

// Evaluate the expression
var result = evaluator.Invoke(context); // 21

Operators

ILMath supports the following operators.

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo
^ Exponentiation

Built-ins

ILMath supports many built-in variables and functions. The following table lists all built-in variables and functions.

Variables

Variable Description
pi The ratio of a circle's circumference to its diameter
e Euler's number
tau The ratio of a circle's circumference to its radius
phi The golden ratio
inf Infinity
nan Not a number
degToRad Conversion factor from degrees to radians
radToDeg Conversion factor from radians to degrees

Functions

Function Description
sin(x) Sine of x in radians
cos(x) Cosine of x in radians
tan(x) Tangent of x in radians
asin(x) Arcsine of x in radians
acos(x) Arccosine of x in radians
atan(x) Arctangent of x in radians
atan2(y, x) Arctangent of y / x in radians
sinh(x) Hyperbolic sine of x in radians
cosh(x) Hyperbolic cosine of x in radians
tanh(x) Hyperbolic tangent of x in radians
sqrt(x) Square root of x
cbrt(x) Cube root of x
root(x, n) nth root of x
exp(x) Exponential function of x
abs(x) Absolute value of x
log(x) Natural logarithm of x
log10(x) Base-10 logarithm of x
log2(x) Base-2 logarithm of x
logn(x, n) Base-n logarithm of x
pow(x, y) x raised to the power of y
mod(x, y) x modulo y
min(x, y) Minimum of x and y
max(x, y) Maximum of x and y
floor(x) Floor of x
ceil(x) Ceiling of x
round(x) Round of x
sign(x) Sign of x
clamp(x, min, max) Clamps x between min and max
lerp(x, y, t) Linear interpolation between x and y by t
inverseLerp(x, y, t) Inverse linear interpolation between x and y by t

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

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
1.2.0 132 1/29/2024
1.1.2 144 1/3/2024
1.1.1 130 10/4/2023
1.1.0 110 10/4/2023
1.0.0 98 10/4/2023