Basic Data Types
Original Blitz has three basic data types: Integer, Float, and String. A value's type determines how it is stored, which operations it supports, and how it is converted when combined with another type.
Extended mode also provides true 64-bit Long and Double basic types.
| Type | Traditional tag | Modern annotation | Default value | Examples |
|---|---|---|---|---|
| Integer | % |
:Int |
0 |
5, -10, 0 |
| Float | # |
:Float |
0.0 |
0.5, -10.1, 3.0 |
| String | $ |
:Str |
"" |
"Hello", "Game Over", "" |
The traditional %, #, and $ tags work
in every dialect. :Int, :Float, and :Str
are available with Dialect
"modern". If no type is stated, a variable, Field, array, parameter, or
Function return value defaults to Integer.
Integer
An Integer is a signed 32-bit whole number. Its range is
-2147483648 to 2147483647. Integer literals have no
decimal point:
Local score% = 1200 Local offset% = -16 Local count% = 0
Comparison and Boolean expressions also produce Integer results:
True is 1 and False is 0. In a
condition, zero is false and any non-zero Integer is true.
Float
A Float is a 32-bit IEEE 754 single-precision number. It can represent a
fractional value and has approximately seven significant decimal digits of
precision, with a maximum finite magnitude of approximately
3.4 × 10^38.
A Float literal includes a decimal point, even when its fractional part is zero:
Local speed# = 2.5 Local temperature# = -10.25 Local origin# = 0.0
Most decimal fractions cannot be represented exactly in binary floating point, so the stored result may be a close approximation.
String
A String contains text. A String literal is enclosed in double quotation
marks, and "" is the empty String:
Local playerName$ = "Ranger" Local message$ = "Ready" Local emptyText$ = ""
The + operator concatenates Strings. Strings may also be
compared using the comparison operators.
Local fullMessage$ = playerName$ + ": " + message$ If playerName$ = "Ranger" Then Print fullMessage$
Declaring types
Traditional type tags follow the identifier:
Local lives% = 3 Local gravity# = 9.8 Local title$ = "Arena"
Modern annotations provide equivalent named forms:
Dialect "modern" Local lives:Int = 3 Local gravity:Float = 9.8 Local title:Str = "Arena"
A type tag or annotation is part of a declaration's type. The same identifier cannot be declared again with a different type. See Variables for declaration and scope rules.
Conversions
Int, Float, and Str explicitly convert a value to the corresponding basic type:
whole% = Int(12.6) decimal# = Float("3.5") text$ = Str(100)
Mixed-type expressions may also convert an operand automatically. See Operators and Conversions for the conversion order and operator rules, and Constants for literal and named-constant syntax.
Other language types
Custom Types store references to structured objects and are not basic values. Extended mode additionally provides Enums, Interfaces, and typed List references; these retain their own type and compatibility rules. It also provides the basic Long and Double types described in Long and Double.