Skip to content

ArithmeticParser

JaykeBird edited this page Feb 21, 2023 · 6 revisions

Back to home | Back to Reference | View raw text

ArithmeticParser class

Description

Contains functionality to parse and evaluate math arithmetic expressions.

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph SolidShineUi
  SolidShineUi.ArithmeticParser[[ArithmeticParser]]
  end
Loading

Members

Methods

Public Static methods

Returns Name
double Evaluate(string input)
Evaluate an arithmetic expression and output the result (i.e. "2+5" will output "7"). See remarks for more info on supported functions.
bool IsValidString(string input)
Check if a string can be parsed as an expression.

Details

Summary

Contains functionality to parse and evaluate math arithmetic expressions.

Methods

Evaluate

public static double Evaluate(string input)
Arguments
Type Name Description
string input The arithmetic expression to evaluate.
Summary

Evaluate an arithmetic expression and output the result (i.e. "2+5" will output "7"). See remarks for more info on supported functions.

Remarks

Supports addition, subtraction, multiplication, division, and exponents. Also supports parantheses (with implied multiplcation) and negative numbers.

Uses order of operations: exponents, division, multiplication, subtraction, addition.

Whitespace and new-line characters are removed prior to evaluation, and the literal characters ×, ⋅, and ÷ are replaced with their representations *, *, and /.

Returns

The result of the expression.

Exceptions
Name Description
FormatException Thrown if the expression is not valid (contains unrecognized characters or a mismatched number of parantheses).

IsValidString

public static bool IsValidString(string input)
Arguments
Type Name Description
string input The string to parse.
Summary

Check if a string can be parsed as an expression.

Returns

True if it is a string that can be parsed. False if it contains invalid characters.

Generated with ModularDoc

Clone this wiki locally