Programmer Guide/Command Reference/INT: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
<var>var</var> := INT <var>expression</var>
{|class="keinrahmen"
<var>var</var> := INTCHECK <var>expression</var>
!command !!return value !!value of RC
|-
|<code><var>var</var> := INT <var>expression</var></code>
|integer part of evaluated ''expression'' or<BR>empty string if the evaluation fails
|error code
|-
|<code><var>var</var> := INTCHECK <var>expression</var></code>
|integer part of evaluated ''expression'' or<BR>empty string if the evaluation fails
|warning code
|}


The <code>INT</code> statement will cause your expression being evaluated as an integer expression. More precisely (more precisely less wrongly), the expression will be evaluated numerically, and the result will be converted to an integer whose textual representation will be the string to be assigned to the destination variable. The calculation itself will be done with the point floating, though (see the below examples for what that means).
The <code>INT</code> statement will cause your expression being evaluated as an integer expression. More precisely (more precisely less wrongly), the expression will be evaluated numerically, and the result will be converted to an integer whose textual representation will be the string to be assigned to the destination variable. The calculation itself will be done with in 64bit floating point, though (see the below examples for what that means).
 
If the evaluation fails, the return value is the empty string (<nowiki>''</nowiki>) and the error information (code and message) is stored in the variables variables


Note that the <code>INT</code> statement converts the result to an integer by ''truncating'' it. There is no rounding involved, no rounding at all.
Note that the <code>INT</code> statement converts the result to an integer by ''truncating'' it. There is no rounding involved, no rounding at all.
Line 17: Line 28:
  #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?


See also: [[Programmer Guide/Command Reference/NUM|NUM]] ([[Programmer Guide/Command Reference/NUMCHECK|NUMCHECK]]), [[Programmer Guide/Command Reference/EVAL|EVAL]] ([[Programmer Guide/Command Reference/EVALCHECK|EVALCHECK]])
;See also: [[../NUM|NUM, NUMCHECK]], [[../EVAL|EVAL, EVALCHECK]]
<!-- C.G. 31.3.2011 -->
<!-- C.G. 31.3.2011 -->

Revision as of 14:48, 21 April 2011

command return value value of RC
var := INT expression integer part of evaluated expression or
empty string if the evaluation fails
error code
var := INTCHECK expression integer part of evaluated expression or
empty string if the evaluation fails
warning code

The INT statement will cause your expression being evaluated as an integer expression. More precisely (more precisely less wrongly), the expression will be evaluated numerically, and the result will be converted to an integer whose textual representation will be the string to be assigned to the destination variable. The calculation itself will be done with in 64bit floating point, though (see the below examples for what that means).

If the evaluation fails, the return value is the empty string ('') and the error information (code and message) is stored in the variables variables

Note that the INT statement 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.

#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?
See also
NUM, NUMCHECK, EVAL, EVALCHECK

Navigation menu

Personal tools