MAINSAIL Language Manual, Section 32.88

previous   next   top   contents   index   framed top   this page unframed


32.88. cvi

Figure 32–91. cvi (GENERIC)
$BUILTIN COMPILETIME
INTEGER
PROCEDURE   cvi         (BITS b);

INTEGER
PROCEDURE   cvi         (STRING s);

$BUILTIN
INTEGER
PROCEDURE   cvi         (REAL x);

$BUILTIN COMPILETIME
INTEGER
PROCEDURE   cvi         (LONG INTEGER i);

$BUILTIN COMPILETIME
INTEGER
PROCEDURE   cvi         (LONG BITS b);

$BUILTIN
INTEGER
PROCEDURE   cvi         (LONG REAL x);

$BUILTIN COMPILETIME
INTEGER
PROCEDURE   cvi         (INTEGER i);

cvi converts to INTEGER.

The LONG INTEGER form converts to a different internal format, if necessary. Overflow is not necessarily detected.

The INTEGER form returns its argument.

The (LONG) REAL forms round x to the nearest INTEGER. If x is exactly halfway between two INTEGERs (i.e., has a fraction of 0.5), the direction of rounding is unspecified. Overflow is not necessarily detected if the floating point number is outside the INTEGER range.

The (LONG) BITS forms convert b to the INTEGER with the corresponding bit pattern, truncated on the left if necessary.

If s is a STRING, i := cvi(s) has the same result as r := s; read(r,i), where r is a temporary STRING variable.

See Figure 35–16 for a table contrasting ceiling, cvi, floor, and truncate.

Example 32–92. Use of cvi
cvi(1876L)                 = 1876
cvi(10.4)                  = 10
cvi(-10.6)                 = -11
cvi(10.5)                  = 10 or 11 (unspecified)
cvi('234)                  = 156
cvi("There are 10 errors") = 10


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Language Manual, Section 32.88