Aptivi - Deprecated Manuals
ProjectsWebsiteBlog
Nitrocid KS v0.1.0 Beta 2 - Manual
Nitrocid KS v0.1.0 Beta 2 - Manual
  • 👋Welcome!
  • Versions and Compatibility
    • 🔱Supported Versions
    • 🕘EOL Versions
    • 🗞️Version Release Notes
      • ✨v0.0.1.x series
      • 🌈v0.0.2.x series
      • 👥v0.0.3.x series
      • 🛠️v0.0.4.x series
      • 🕔v0.0.5.x series
        • ⌚v0.0.5.0 Beta Versions
      • 📕v0.0.6.x series
        • 📄v0.0.6.0 Beta Versions
      • 🔌v0.0.7.x series
        • ⚡v0.0.7.0 Beta Versions
      • 🌌v0.0.8.x series
      • 💌v0.0.9.x series
      • 📜v0.0.10.x series
      • ✏️v0.0.11.x series
      • ⚙️v0.0.12.x series
      • 🌐v0.0.13.x series
      • 🏃♀ v0.0.14.x series
      • ⏳v0.0.15.x series
      • ⭐v0.0.16.x series
      • 🌃v0.0.17.x series
      • 🥁v0.0.18.x series
      • 🔧v0.0.19.x series
      • 🍀v0.0.20.x series
      • 🧰v0.0.21.x series
      • 📱v0.0.22.x series
      • 🖥️v0.0.23.x series
      • 👾v0.0.24.x series
      • 🔮v0.1.x.x series
        • ⚠️Known issues for 0.1.0 Beta
    • 👍Compatibility Notes for KS API Revisions
      • 🔼Upgrading from API v1.0
      • 🔼Upgrading from API v1.1
      • 🔼Upgrading from API v1.2
      • 🔼Upgrading from API v1.3
      • 🔼Upgrading from API v2.0
      • 🔼Upgrading from API v2.1
      • 🔼Upgrading to API v3.0
  • Installation and Maintenance
    • 📀Installing the Kernel
      • 💻Windows
      • 🐧Linux
      • 📱Android
    • ⏫Upgrading the Kernel
      • 💻Windows
      • 🐧Linux
      • 📱Android
  • Fundamentals
    • 🌽What is the Kernel?
    • 👾What is Nitrocid KS?
    • 🌟Simulated Kernel Features
      • 👤Accounts
        • 🔓Permissions
      • 🐚Shells
      • 🌍Networking
        • 🗃️FTP Client
        • 🔒SFTP Client
        • 📰RSS Client
        • 🌐HTTP Client
        • 📧Mail Client
      • ✏️Editors
        • 📝Text Editor
        • 🖊️JSON Editor
        • 💾Hex Editor
      • 🇺🇸 Languages
      • 🌌Screensavers
      • 🎮Games and Amusements
        • 🔤Hangman
        • ☄️Meteor
        • 🐍Snaker
        • 🔢Solver
        • ⌨️SpeedPress
        • 🔠Wordle
      • 🗓️Calendar
      • ⏰Stopwatch and Timer
      • ⚖️Calculator and Converter
  • Advanced and Power Users
    • ⚒️Building the Kernel
      • 🪟Building on Windows
      • 🐧Building on Linux
    • 🧰Kernel Modifications
      • 🔧Kernel Modification Management
      • 🏗️Build your...
        • 🧪Your Mod
        • 🌌Your Screensaver
        • 🪄Your Splash
    • 🦠Diagnostics
      • 🔬Debugging
        • 🧬Local Debugging
        • 🛰️Remote Debugging
      • 🧪Testing
      • 💉Other Diagnostics
    • ⚒️Inner Workings
      • 🔧Kernel Settings
        • ⛏️Mechanics of Settings App
        • 🔩Settings Format
      • 🐚Shell Structure
        • ❔Help System
        • 🗜️Command Parsing
        • 📜Shell Scripting
      • 🪧Kernel Placeholders
      • 🔐The Permissions
      • 📞Kernel Threads
      • 🔌Kernel Drivers
      • ⚙️Multilingual Kernel Flow
      • 🌐Custom Languages
      • 📽️Presentation System
      • 🎛️Kernel Arguments
      • 📡Remote Procedure
    • 💿GRILO Bootloader and KS
  • 🧱Project Dependencies
  • Report an issue
  • Source code
  • API Reference
Powered by GitBook
On this page
Edit on GitHub
  1. Fundamentals
  2. Simulated Kernel Features

Calculator and Converter

Calculate your mathematical expressions and convert units

Last updated 1 year ago

The calculator is used to perform arithmetic operations, ranging from the simplest operations to the most complex ones, powered by the StringMath library. Its syntax reference can be reviewed in the below link to the official library documentation.

The unit converter, however, is used to easily convert the source units to different units, like centimeters to meters. It's powered by the UnitsNet library. You can consult the list of units UnitsNet supports here:

To use both the programs, refer to the command usages and individual explanations below.

  • calc <expression>

    • Calculates the specific arithmetical expression

  • unitconv <unittype> <quantity> <sourceunit> <targetunit>

    • Converts the unit by quantity and type from the source unit to the target unit

You can use the listunits command to get all the available units by type.

🌟
⚖️
https://github.com/angularsen/UnitsNet/tree/master/UnitsNet/GeneratedCode/Units
https://github.com/miroiu/string-math/blob/master/README.md
> V3 README can be found here: <https://github.com/miroiu/string-math/tree/release-3.0.0>

> **NEW!** Boolean math example: https://github.com/miroiu/string-math/pull/6/files

# String Math [![NuGet](https://img.shields.io/nuget/v/StringMath?style=flat-square&logo=nuget)](https://www.nuget.org/packages/StringMath/) [![Downloads](https://img.shields.io/nuget/dt/StringMath?label=downloads&style=flat-square&logo=nuget)](https://www.nuget.org/packages/StringMath) ![.NET](https://img.shields.io/static/v1?label=%20&message=Framework%204.6.1%20to%20NET%208&color=5C2D91&style=flat-square&logo=.net) ![](https://img.shields.io/static/v1?label=%20&message=documentation&color=yellow&style=flat-square)

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

```csharp
double result = "1 * (2 - 3) ^ 2".Eval(); // 1
```

## Variables

```csharp
double result = "{a} + 2 * {b}".Substitute("a", 2).Substitute("b", 3).Result; // 8
```

### Global variables

These variables are inherited and cannot be substituted.

```csharp
MathExpr.AddVariable("PI", 3.1415926535897931);
double result = "1 + {PI}".Eval(); // 4.1415926535897931
```

## Custom operators

### Global operators

These operators are inherited and can be overidden.

```csharp
MathExpr.AddOperator("abs", a => a > 0 ? a : -a);
double result = "abs -5".Eval(); // 5

// Operator precedence (you can specify an int for precedence)
MathExpr.AddOperator("max", (a, b) => a > b ? a : b, Precedence.Power);
double result = new MathExpr("2 * 3 max 4").Result; // 8
```

### Local operators

These are applied only to the target expression.

```csharp
MathExpr expr = "{PI} + 1";
expr.SetOperator("+", (a, b) => Math.Pow(a, b));
double result = expr; // 3.1415926535897931

double result2 = "{PI} + 1".Eval(); // 4.1415926535897931
```

## Advanced

### Extract variables

```csharp
var expr = "{a} + {b} + {PI}".ToMathExpr();
var variables = expr.Variables; // { "a", "b", "PI" }
var localVariables = expr.LocalVariables; // { "a", "b" }
```

### Compilation

```csharp
Func<double, double> fn = "{a} + 2".ToMathExpr().Compile("a");
double result = fn(5); // 7
```

### Conditional substitution

```csharp
MathExpr expr = "1 / {a}".Substitute("a", 1);

double temp = expr.Result; // 1

if (someCondition)  // true
 expr.Substitute("a", 2);

double final = expr.Result; // 0.5
```

### Sharing math context

```csharp
MathExpr expr = "{PI} + 1";
expr.SetOperator("+", (a, b) => Math.Pow(a, b));

MathExpr expr2 = "3 + 2".ToMathExpr(expr.Context);

double result = "1 + 2 + 3".Eval(expr.Context);
```

### Custom math context

```csharp
var context = new MathContext(); // new MathContext(MathContext.Default); // to inherit from global
context.RegisterBinary("+", (a, b) => Math.Pow(a, b));

MathExpr expr = new MathExpr("{PI} + 1", context);
MathExpr expr2 = "3 + 2".ToMathExpr(context);
double result = "1 + 2 + 3".Eval(context);
```

## Default operators

### Binary

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

### Unary

```csharp
- (negation)
! (factorial)
sqrt (square root)
sin (sine)
asin (arcsine)
cos (cosine)
acos (arccosine)
tan (tangent)
atan (arctangent)
rad (convert degrees to radians)
deg (convert radians to degrees)
ceil (ceiling)
floor (floor)
round (rounding)
exp (e raised to power)
abs (absolute)
```