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.
| Type | Bytes | Holds |
|---|---|---|
int8 int16 int32 int64 | 1 2 4 8 | signed whole numbers |
uint8 uint16 uint32 uint64 | 1 2 4 8 | whole numbers from 0 up |
float32 float64 | 4 8 | floating point, about 7 and 16 digits |
boolean | 1 | true or false |
ustring | text 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
- Add an
int16set to -32768 and auint16set to 65535 to the table. - Add a row for
integerand compare its size withint64.