Programmer Guide/Command Reference/INT: Difference between revisions
From STX Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE: | {{DISPLAYTITLE:INT, INTCHECK}} | ||
{|class=" | {|class="einrahmen" | ||
!command !!return value !!value of RC | !command !!return value !!value of RC | ||
|- | |- | ||
|<code> | |<code>INT <var>expression</var></code> | ||
|integer part of evaluated ''expression'' or<BR>empty string if the evaluation fails | |integer part of evaluated ''expression'' or<BR>empty string if the evaluation fails | ||
|error code | |0<BR>error code | ||
|- | |- | ||
|<code> | |<code>INTCHECK <var>expression</var></code> | ||
|integer part of evaluated ''expression'' or<BR>empty string if the evaluation fails | |integer part of evaluated ''expression'' or<BR>empty string if the evaluation fails | ||
|warning code | |0<BR>warning code | ||
|} | |} | ||
;Description: The ''expression'' will be evaluated numerically, and the result will be converted to an integer whose textual representation is the return value. The calculation itself will be done with floating point accuracy. The same evaluation rules as defined for the [[../NUM|NUM command]] apply to this command. | |||
The | ;Notes: | ||
:* The <code>INT</code> 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 (<code>INT</code>) or warning (<code>INTCHECK</code>) is reported. | |||
;See also: [[../NUM|NUM, NUMCHECK]], [[../EVAL|EVAL, EVALCHECK]], [[../SEGMENT|SEGMENT]] | |||
;Examples: | |||
In case of the expression being syntactically ill-formed, an error (<code>INT</code>) or warning (<code>INTCHECK</code>) is reported. | |||
#result := int 3.1 // #result is set to 3 | #result := 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 | ||
Line 27: | Line 24: | ||
// compare the preceding example with the following one: | // compare the preceding example with the following one: | ||
#result := int 3 * int(3.9) // here, #result will be assigned 9 - cool, isn't it? | #result := int 3 * int(3.9) // here, #result will be assigned 9 - cool, isn't it? | ||
Latest revision as of 10:49, 26 April 2011
command | return value | value of RC |
---|---|---|
INT expression
|
integer part of evaluated expression or empty string if the evaluation fails |
0 error code |
INTCHECK expression
|
integer part of evaluated expression or empty string if the evaluation fails |
0 warning code |
- Description
- The expression will be evaluated numerically, and the result will be converted to an integer whose textual representation is the return value. The calculation itself will be done with floating point accuracy. The same evaluation rules as defined for the NUM command apply to this command.
- 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, SEGMENT
- 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?