Show / Hide Table of Contents

Class MathExpression

Simple math expression parser and evaluator

Inheritance
object
MathExpression
Namespace: ABB.Robotics.Math
Assembly: ABB.Robotics.Math.dll
Syntax
public class MathExpression
Remarks

Literal values should be using '.' as a decimal separator.

Constructors

View Source

MathExpression(double)

Creates a simple MathExpression from the given value

Declaration
public MathExpression(double val)
Parameters
Type Name Description
double val

Value to build expression for

Remarks

Calling Evaluate() will return the given value

View Source

MathExpression(double, int)

Creates a simple MathExpression from the given value with the specified number of decimals

Declaration
public MathExpression(double val, int numDecimals)
Parameters
Type Name Description
double val

Value to build expression for

int numDecimals

Maximum number of decimals to use

Remarks

Calling Evaluate() will return the given value (rounded to the given number of decimals).

View Source

MathExpression(string)

Creates a new MathExpression class from a mathematical expression

Declaration
public MathExpression(string expression)
Parameters
Type Name Description
string expression
View Source

MathExpression(string, bool)

Creates a new MathExpression class from a mathematical expression, optionally converting arguments of trigonometric functions from degrees

Declaration
public MathExpression(string expression, bool convertDegrees)
Parameters
Type Name Description
string expression

The mathematical expression

bool convertDegrees

If true convert the arguments of trigonometric functions from degrees to radians

Properties

View Source

ErrorText

If the expression is invalid (IsValid returns false), this property may return more information why.

Declaration
public string ErrorText { get; }
Property Value
Type Description
string
View Source

ExpressionString

Gets or sets the source expression string

Declaration
public string ExpressionString { get; set; }
Property Value
Type Description
string
View Source

IsSimple

Returns True if the expression consists of a single value

Declaration
public bool IsSimple { get; }
Property Value
Type Description
bool
View Source

IsValid

Returns True if the expression is valid and can be evaluated

Declaration
public bool IsValid { get; }
Property Value
Type Description
bool
View Source

VariableNames

Returns the names of variables used in the expression

Declaration
public IEnumerable<string> VariableNames { get; }
Property Value
Type Description
IEnumerable<string>

Methods

View Source

Evaluate()

Evaluates the expression

Declaration
public double Evaluate()
Returns
Type Description
double

The evaluated value of the expression

View Source

Evaluate(IDictionary<string, double>)

Evaluates the expression, using the passed in dictionary of variable values

Declaration
public double? Evaluate(IDictionary<string, double> variableValues)
Parameters
Type Name Description
IDictionary<string, double> variableValues
Returns
Type Description
double?

The evaluated value of the expression

Remarks

This overload is thread-safe, as long as no other methods on this class are called concurrently.

View Source

GetAllowedOperators()

Returns the allowed operators

Declaration
public static string[] GetAllowedOperators()
Returns
Type Description
string[]
View Source

GetLinearCoefficients(string[])

Returns the linear coefficients, if this expression is linear in the set of given variables. Otherwise it returns null.

Declaration
public double[] GetLinearCoefficients(string[] variables)
Parameters
Type Name Description
string[] variables
Returns
Type Description
double[]
View Source

SetVariableValue(string, double)

Sets the value of a variable, which will be used the next time the expression is evaluated.

Declaration
public void SetVariableValue(string variable, double val)
Parameters
Type Name Description
string variable

Name of the variable to set

double val

New value of the variable

View Source

TrySetVariableValue(string, double)

Sets the value of a variable, which will be used the next time the expression is evaluated.

Declaration
public bool TrySetVariableValue(string variable, double val)
Parameters
Type Name Description
string variable

Name of the variable to set

double val

New value of the variable

Returns
Type Description
bool

True if the variable could be set (i.e. if it exists), false otherwise

  • View Source
In this article
Back to top Copyright © 2025 ABB