Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Primitives

tiko's built-in scalar types put their size in their name: int8 to int64 for signed integers, uint8 to uint64 for unsigned ones, float32 and float64 for floating point. boolean holds true or false, and ustring holds text.

#import "std/strings"

'' The scalar types say how big they are in their names.
dim as int8    tiny  = -128
dim as int16   small = 32767
dim as int32   count = 2147483647
dim as int64   huge  = 9223372036854775807
dim as uint8   octet = 255
dim as uint64  mask  = &hFFFFFFFFFFFFFFFF
dim as float32 ratio = 0.75
dim as float64 pi    = 3.141592653589793
dim as boolean ready = true

print strings.Format( "{:<8} {:>5}  {}", "type", "bytes", "value" )
print strings.Format( "{:<8} {:>5}  {}", "int8", sizeof( tiny ), tiny )
print strings.Format( "{:<8} {:>5}  {}", "int16", sizeof( small ), small )
print strings.Format( "{:<8} {:>5}  {}", "int32", sizeof( count ), count )
print strings.Format( "{:<8} {:>5}  {}", "int64", sizeof( huge ), huge )
print strings.Format( "{:<8} {:>5}  {}", "uint8", sizeof( octet ), octet )
print strings.Format( "{:<8} {:>5}  {}", "uint64", sizeof( mask ), mask )
print strings.Format( "{:<8} {:>5}  {}", "float32", sizeof( ratio ), ratio )
print strings.Format( "{:<8} {:>5}  {}", "float64", sizeof( pi ), pi )
print strings.Format( "{:<8} {:>5}  {}", "boolean", sizeof( ready ), ready )

'' Text is a ustring: a sequence of characters that grows as needed.
dim as ustring label = "primitive"
print strings.Format( "label is {}, {} characters", label, len( label ) )

Output

type     bytes  value
int8         1  -128
int16        2  32767
int32        4  2147483647
int64        8  9223372036854775807
uint8        1  255
uint64       8  18446744073709551615
float32      4  0.75
float64      8  3.141592653589793
boolean      1  true
label is primitive, 9 characters

sizeof gives the size of a value's type in bytes. Each width is the same on every target, so an int32 is four bytes on Windows and on Linux alike.

TypeBytesHolds
int8 int16 int32 int641 2 4 8signed whole numbers
uint8 uint16 uint32 uint641 2 4 8whole numbers from 0 up
float32 float644 8floating point, about 7 and 16 digits
boolean1true or false
ustringtext of any length

Two more integer types, integer and uinteger, are as wide as an address on the target; Sizes shows them. A ustring is text, not a scalar: len( label ) counts its characters, and Strings covers it properly.

The pages in this section cover how to write values (literals), what you can do with them (operators), and two ways to group them: tuples and fixed-size arrays.

Activities

  1. Add an int16 set to -32768 and a uint16 set to 65535 to the table.
  2. Add a row for integer and compare its size with int64.