NUM, NUMCHECK
From STX Wiki
Jump to navigationJump to search
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:
- numbers
decimal 123.456, 17.5e3, 100, -312.123, 1e-3
hexa-decimal 0x1234, 0xabc, 0XabC
special constants pi
(=3.1415...)e
(=2.71828...)rand
(a linear distributed pseudo random number in the range -1..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
- functions
- Notes
-
- The
INT
command converts the result to an integer by truncating it. There is no rounding involved, no rounding at all. - In case of the expression being syntactically ill-formed, an error (
INT
) or warning (INTCHECK
) is reported.
- The
- See also
- NUM, NUMCHECK, EVAL, EVALCHECK
- Examples
#result := 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?