ILMath 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ILMath --version 1.0.0
                    
NuGet\Install-Package ILMath -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="ILMath" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ILMath" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ILMath" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ILMath --version 1.0.0
                    
#r "nuget: ILMath, 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.
#:package ILMath@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ILMath&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ILMath&version=1.0.0
                    
Install as a Cake Tool

⚡ 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
var evaluator = MathEvaluation.CompileExpression("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
deg_to_rad Conversion factor from degrees to radians
rad_to_deg 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

MIT License

Copyright (c) 2023 Reimnop

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.5.0 301 7/25/2024
1.4.0 137 7/21/2024
1.3.1 138 7/21/2024
1.3.0 139 7/21/2024
1.2.0 206 1/29/2024
1.1.2 214 1/3/2024
1.1.1 198 10/4/2023
1.1.0 164 10/4/2023
1.0.0 155 10/4/2023