user manual
141
CLEM Language Reference
Function
Result
Description
integer_bitcount(INT)
Integer
Counts t he number of 1 or 0 bits in the
two’s-com plement representation of INT. If
INT is non-negative, N is the number of 1 bits. If
INT is negative, it is the number of 0 bits. Owing to
the sign extens i on, there are an infinite number of 0
bits in a non-negative integer or 1 bits in a negative
integer. It is always the case that integer_bitcount(INT)
= integer_bitcount(-(INT+1)).
integer_leastbit(INT)
Integer
Returns the bit position N of the least-signi ficant bit
set in the integer INT. N is the highest power of 2 by
which INT divides exactly.
integer_length(INT)
Integer
Returns the lengt h in bits of INT as a two’s-complement
integer. That is, N is the smallest integer such that INT
< (1 << N) if INT >= 0 INT >= (–1 << N) if INT < 0. If
INT is non-negative, then th e representation of INT as
an unsigned integer requires a field of at least N bits.
Alternatively, a minimum of N+1 b i t s is required to
represent INT as a signed integer, regardless of its sign.
testbit(INT, N)
Boolean
Tests the b i t at position N in the integer INT and returns
the state of bit N as a B oolean value, which is true for 1
and false for 0.
Random Functions
The following functions are used to randomly s elect items or randomly generate numbers.
Function
Result
Description
oneof(LIST)
Any
Returns a rand omly chosen element of LIST. List items should
be entered as [ITEM1,ITEM2,...,ITEM_N]. Note that a list of field
names can also be specified. For more informati on, see the
topic Summarizing Multiple Fields in Chapter 7 on p. 115.
random(NUM)
Number
Returns a uniformly distributed random number of the same type
(INT or REAL), sta rting from 1 to NUM. If you use an integer,
then onl
y integers are returned. If you use a real (deci mal)
number, then real numbers are returned (decimal precision
determined by the stream opt i ons). The largest random number
return
ed by the function could equal NUM.
random0(NUM)
Number
This has th e same properties as random(NUM), but starting from
0. The largest random number returned by the function will
never equal X.
String Functions
In CLEM
, you can perf orm the following operations with strings:
Compare string s
Creat
e strings
Access characters