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
.
mod
Integer modulo. Returns r
in the previous equation (see Operator /
)
<<
Left shift
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.1 Introduction
Next : 1.3 Map