IKC3 supports all C integer type sizes from U8 (matching the C type uint8_t)
to U64 (matching the C type uint64_t) for unsigned integers,
and from S8 to S64 for signed integers.
In addition to these 8 basic integer types there are 2 pointer-sized
integer types :
Uw for unsigned pointer-sized integers,
and Sw for signed pointer-sized integers.
Small integers take little space, are static, they are passed directly and not as a pointer, and for these reasons are fast.
They do not need to be cleaned after use and thus can be used in arrays like is usually done in C.
ikc3> type(-1)
S8
ikc3> type(-128)
S16
ikc3> type(-32768)
S32
ikc3> type(-2147483648)
S64
ikc3> type(-9223372036854775807)
S64
ikc3> type(0)
U8
ikc3> type(256)
U16
ikc3> type(65536)
U32
ikc3> type(4294967296)
U64
ikc3> type(18446744073709551615)
U64
IKC3 supports large integers and they are compatible with small integers.
Their type is Integer and can support numbers as large as memory allows.
They are slow because they are allocated dynamically on the heap
using malloc.
ikc3> type(1000000000000000000000000000000)
Integer
~Binary not.
ikc3> ~ 1
254
ikc3> ~ -1
0
ikc3> ~ 0
255
ikc3> ~ 255
0
ikc3> ~ (U16) 1
65534
ikc3> ~ (S16) 1
-2
+Integer addition.
All positive integers can be defined in terms of addition of : zero or a positive integer, and one. E.g.
1 = 0 + 1
2 = 0 + 1 + 1
3 = 0 + 1 + 1 + 1
etc.
-Integer subtraction. Take an integer and remove another integer from it.
*Integer multiplication. Init result to zero, add an integer a and
repeat b times.
/Integer division. The inverse of multiplication :
for all integers a and b there is a couple q and r that satisfies
a = b * q + r. Integer division returns q.
For integer operands, a zero divisor reports an error.
Dividing a signed minimum by -1 returns its exact positive value in a
suitable unsigned integer type, for example (S8) -128 / (S8) -1 is 128.
modInteger modulo. Returns r in the previous equation (see Operator /).
For integer operands, a zero divisor reports an error.
A signed minimum modulo -1 returns zero. % is an alias for mod.
<<Left shift. Fixed-width operands retain their type and width; bits shifted
past that width are discarded. Signed values use their two's-complement
bit representation, so (S8) 64 << 1 returns (S8) -128.
Both shift operators require a non-negative integer count. The count's
type does not change the result type. For a fixed-width operand, a count
at least as large as its width returns zero, except that a negative value
shifted right returns minus one. Bool inputs are normalized to zero or
one and use eight-bit result storage; Character uses 32 bits.
Integer left shifts are exact, subject to available memory and the
backend's bit capacity. An unrepresentable result fails; shifting zero
left by any non-negative count returns zero.
>>Right shift. Unsigned fixed-width values shift in zero bits. Signed
fixed-width values and Integer values extend the sign, rounding toward
negative infinity: (S8) -3 >> 1 and (Integer) -3 >> 1 both return -2.
Counts beyond an Integer's bit length return zero or minus one directly.
ikc3> type(1)
U8
ikc3> type(1000000000000000000000000000000)
Integer
ikc3> a = 1 + 100000000000000000000000000000000
100000000000000000000000000000001
ikc3> a * a
10000000000000000000000000000000200000000000000000000000000000001
ikc3> a * a / 1000000000000000000000000000000000000000000000000000
10000000000000
Top : KC3 documentation
Previous : 1.13 Ident
Next : 1.15 List