Numerical Expressions

From STX Wiki
Jump to navigationJump to search

This STx-related article may be outdated.

General

A numerical expression is a combination of symbols which represent some numerical value. In STx numerical expressions can be used in many places (e.g. in evaluation commands, as an argument, ...) and may contain the following parts:

  • any integer or decimal number
  • the contents of a numerical variable
  • the operators addition '+', subtraction '-', multiplication '*', division '/', modulus '%', logical and '&', logical or '|', power '^' , NOT '!' , unary minus '-' and parenthesis '(' and ')'.
  • mathematical functions

All calculations are performed using 64 bit floating point numbers. Since the default data format in STx macros is the string, the commands NUM, INT or EVAL must be used to evaluate numerical expressions when assigning them to a variable (e.g. '#value := PI' assigns the string 'PI' to '#value', whereas '#value := NUM PI' assigns '3.14159' to '#value').

If you use the EVAL command, you can also perform calculations using vectors and matrices. Please see the EVAL command documentation in the Command Reference for details.

The conversion to (32 bit) integer values is performed (if necessary) after expression evaluation.

Expressions should be enclosed in quotes to allow blanks inside the expression and to disable parsing of special characters (e.g. the slash '/', which is used in expressions as divide-operator and in commands to mark options).

Operators

The following operators are supported:

Unary Operators
sign - -expr
logical not ! !expr


Binary Operators
add + exprA+exprB
subtract - exprA-exprB
multiply * exprA*exprB
divide / exprA/exprB
modulus % exprA%exprB
power ^ exprA^exprB
logical and & exprA&exprB
logical or exprA|exprB


Precedence

Precedence of operators (Operators on the same level are evaluated from left to right):


  • parenthesis ( )
  • unary minus '-', logical not '!'
  • power '^', logical and '&', logical or '|'
  • multiplication '*', division '/', modulus '%'
  • addition '+', subtraction '-'

Functions

The following mathematical functions are available in numerical expressions:

abs

The absolute value of x.{| |- |Usage: |abs(x) |- |Arguments: |{| |- |x |A numerical value. |}


| |}


acos

The inverse cosine of x.{| |- |Usage: |acos(x) |- |Arguments: |{| |- |x |-1 <= x <= 1 |}


| |}


asin

The inverse sine of x.{| |- |Usage: |asin(x) |- |Arguments: |{| |- |x |-1 <= x <= 1 |}


| |}


atan

The inverse tangent of x.

Usage: atan(x)
Arguments:
x A numerical value.


| |}


bark2hz

Computes the Hertz equivalent of the Bark value x.{| |- |Usage: |bark2hz(x) |- |Arguments: |{| |- |x |A numerical value in Bark |}


| |}


bit

Computes 2 ^ x (0 <= x < 32). Use this to compute bit masks.

Usage: bit(x)
Arguments:
x An integer value (0 <= x <= 32).


| |}


cos

The cosine of x.{| |- |Usage: |cos(x) |- |Arguments: |{| |- |x |A value in radians. |}


| |}


db

The value of x in converted thus: 10 ^ (x / 20)

Usage: db(x)
Arguments:
x A numerical value.


| |}


exp

The value e raised to the power of x.{| |- |Usage: |exp(x) |- |Arguments: |{| |- |x |a numerical value |}


| |}


floor

The floor of x.{| |- |Usage: |floor(x) |- |Arguments: |{| |- |x |any real number |}


| |}


hz2bark

Computes the Bark equivalent of the Hertz value x.{| |- |Usage: |hz2bark(x) |- |Arguments: |{| |- |x |A numerical value in Hertz (0 <= x <= 20000). |}


| |}


int

The integer value of x. This function truncates the value x.{| |- |Usage: |int(x) |- |Arguments: |{| |- |x |A numerical value. |}


| |}


ln

The natural logarithm of x.{| |- |Usage: |ln(x) |- |Arguments: |{| |- |x |A numerical value (x > 0) |}


| |}


log

The 10 base logarithm of the argument x.{| |- |Usage: |log(x) |- |Arguments: |{| |- |x |A numerical value (x > 0) |}


| |}


lran

A linear distributed random number (Interval = [0,1]).

pi

The constant p to 16 decimal places.

round

Round the number x to the nearest integer.{| |- |Usage: |round(x) |- |Arguments: |{| |- |x |The value to round. |}


| |}



setlran

Set the random seed for the lran function to x or the current time.

Usage: setlran(x)
Arguments:
x Set the random seed to the current time (x = 0) or to the value of x (0 < x < 1).


| |}


sign

-1 if x is negative, otherwise 1.

Usage: sign(x)
Arguments:
x A numerical value.


| |}


sin

The sine of x.{| |- |Usage: |sin(x) |- |Arguments: |{| |- |x |A value in radians. |}


| |}


sinc

The sinc function of x.

Usage: sinc(x)
Arguments:
x A numerical value


| |}


sinx

1 if x = 0, otherwise sin(x)/x{| |- |Usage: |sinx(x) |- |Arguments: |{| |- |x |A numerical value. |}


| |}


sqrt

The square root of x.{| |- |Usage: |sqrt(x) |- |Arguments: |{| |- |x |A numerical value. |}


| |}


tan

The tangent of x.{| |- |Usage: |tan(x) |- |Arguments: |{| |- |x |A value in radians. |}


| |}

Navigation menu

Personal tools