Programmer Guide/Command Reference/NUM: Difference between revisions
From STX Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
| Line 84: | Line 84: | ||
;Notes: | ;Notes: | ||
:*In case of the expression being syntactically ill-formed, an error (<code>INT</code>) or warning (<code>INTCHECK</code>) is reported. | :*In case of the expression being syntactically ill-formed, an error (<code>INT</code>) or warning (<code>INTCHECK</code>) is reported. | ||
:*The special numerical objects (vectors, matrices) available in [[../EVAL|EVAL]-expressions, can not be used in the <code>NUM</code> expressions. Only the use of numerical constants and variables is possible. | |||
:*The same expression syntax is used for the [[../INT|INT and INTCHECK]] command and for the numerical expressions in [[Programmer_Guide/Introduction#Conditional_Expressions|conditions]] (e.g. [[../IF|IF]] or [[../WHILE|WHILE]]). | :*The same expression syntax is used for the [[../INT|INT and INTCHECK]] command and for the numerical expressions in [[Programmer_Guide/Introduction#Conditional_Expressions|conditions]] (e.g. [[../IF|IF]] or [[../WHILE|WHILE]]). | ||
:*Numerical expressions are evaluated in 64bit floating point precission. | :*Numerical expressions are evaluated in 64bit floating point precission. | ||
| Line 89: | Line 90: | ||
;See also: [[../INT|INT, INTCHECK]], [[../EVAL|EVAL, EVALCHECK]], [[../SEGMENT|SEGMENT]] | ;See also: [[../INT|INT, INTCHECK]], [[../EVAL|EVAL, EVALCHECK]], [[../SEGMENT|SEGMENT]] | ||
;Examples: | ;Examples: | ||
# | #x := int 3.1 // #result is set to 3 | ||
#result := int 3.9 // #result is set to 3, too | #result := int 3.9 // #result is set to 3, too | ||
#result := int 3.9 * 3.9 // #result is set to 15 (note that calculation | #result := int 3.9 * 3.9 // #result is set to 15 (note that calculation | ||
Revision as of 11:16, 26 April 2011
| command | return value | value of RC |
|---|---|---|
NUM expression
|
value of expression or empty string if the evaluation fails |
0 error code |
NUMCHECK expression
|
value of expression or empty string if the evaluation fails |
0 warning code |
- Description
- The expression will be evaluated numerically, and the result (textual representation) will be returned. The expression may consist of the following parts:
- decimal numbers
123.456, 17.5e3, 100, -312.123, 1e-3- hexa-decimal numbers
0x1234, 0xabc, 0XabC- special constants
pi(=3.1415...),e(=2.71828...),rand(a linear distributed pseudo random number r; -1≤r<1)lran(a linear distributed pseudo random number r; 0≤r<1)- numerical operators
-a(negate),a+b(add),a-b(subtract),a*b(multiply),a/b(divide),a%b(modulo),a^b (power)- logical operators (bitwise)
!a(not),a&b(and),a|b(or),a^b(exclusive or)- brackets
(expression)- functions
setlran(seed)linear distributed pseudo random number r (0≤r<1)
seed is the start value (0≤seed<<1)sin(x), cos(x), tan(x)sine, cosine or tangent of x asin(x), acos(x), atan(x)inverse sine, cosine or tangent of x exp(x)computes exlog(x)common logarithm of x (base 10)ln(x)natural logarithm of x (base e)sqrt(x)square root of x (base 10) abs(x)absolute value of x (base 10) int(x)integer part of x, the fractional part is truncated
(range of x: 32bit signed integer)round(x)round to the nearest integer of x
(range of x: 32bit signed integer)db(x)convert level to factor ( 10x/20)sinc(x), sinx(x)sinc function: sin(x) / xsign(x)sign of x; returns -1 if x<0, otherwise 1hz2bark(x)convert x from Hertz to Bark bark2hz(x)convert x from Bark to Hertz bit(n)returns the integer with only bit n (0≤n<32) is set and all other are cleared; can be used to generate bit masks floor(x)returns a floating-point value representing the largest integer that is less than or equal to x
(range of x: 64bit float)iserr(rc), iserror(rc)returns 1 if rc is a STx error code, otherwise 0
this function can be used to test the completion codeRCof a commandiswarn(rc), iswarning(rc)returns 1 if rc is a STx warning code, otherwise 0
this function can be used to test the completion codeRCof a commandnpow2(n)next power of 2; returns the smallest possible value 2m ≥ n
- Notes
-
- In case of the expression being syntactically ill-formed, an error (
INT) or warning (INTCHECK) is reported. - The special numerical objects (vectors, matrices) available in [[Programmer Guide/Command Reference/EVAL|EVAL]-expressions, can not be used in the
NUMexpressions. Only the use of numerical constants and variables is possible. - The same expression syntax is used for the INT and INTCHECK command and for the numerical expressions in conditions (e.g. IF or WHILE).
- Numerical expressions are evaluated in 64bit floating point precission.
- For logical (operators
!, &, |, ^) and integer expressions (functionsround, int, bit) 32bit signed integers are used.
- In case of the expression being syntactically ill-formed, an error (
- See also
- INT, INTCHECK, EVAL, EVALCHECK, SEGMENT
- Examples
#x := int 3.1 // #result is set to 3
#result := int 3.9 // #result is set to 3, too
#result := int 3.9 * 3.9 // #result is set to 15 (note that calculation
// is done in floating point, resulting in 15.21,
// and truncation occurs only on assigning
// compare the preceding example with the following one:
#result := int 3 * int(3.9) // here, #result will be assigned 9 - cool, isn't it?