Table of Contents
Table 2.1. Kenya Primitive Types
Name | Description | Range of values | Default value |
---|---|---|---|
boolean | Represents an elementary truth value. | One of the literals true or false | The literal false |
char | Represents a single character literal. This is stored as a 16bit number. | Numerically: 0 to 65535 (but see notes below) | Numerical 0 or as a literal ( see below ) '\0' |
int | Represents an integer (whole) number. This is stored as a 32bit 2's complement number. | -2147483648 to 2147483647 | 0 |
double | Represents a floating point number to "double precision". This is stored as a 64bit number. | 4.9E-324 to 1.7976931348623157E308 | 0 |
Since the primitive types are built into Kenya, there is special syntax for declaring their 'values' in your programs.
A boolean has only one of two values, true or false, and so you can write true or false directly in your source code.
A character is technically a number, but usually you use it to store a single character, like A, B etc. To facilitate this, you can include a single character ( in the ASCII range ) directly in your source code by surrounding it in ' marks. You may also wish to include some special characters (like a newline or tab), and this is done using special escape sequences, these are explained in the table below:
Table 2.2. Kenya Character Escape Sequences
Escape Sequence | Description |
---|---|
'\0' | The character with the numeric value of 0 |
'\b' | Represents backspace |
'\t' | Represents a tab character |
'\n' | Represents a linefeed character (newline) |
'\f' | Represents a formfeed character |
'\r' | Represents a carriage return character |
'\"' | Represents a double quote symbol (") |
'\'' | Represents a single quote symbol (') |
'\\' | Represents a backslash symbol (\) |
Because char's, int's and double's all represent numbers, it is possible in certain circumstances to use one to represent another. Without any extra syntax, you can use a char anywhere where you would need an int or double, or an int anywhere where you would need a double. This is called a widening conversion and happens automatically. To go the other way, use the round, ceil, floor, and toChar functions that are built into Kenya.