Appearance
Working with Data Types
Data types form the foundation of Coldwave Script. Unlike in many high-level languages, they directly influence safety and predictability: integers saturate instead of overflowing, floating-point values follow IEEE rules, time types support precise control logic, and type conversions are strictly defined. Understanding these rules helps avoid surprises and enables deterministic programming.
Integers (signed/unsigned, promotion, overflow)
INT = 16-bit (−32768 … +32767), UINT = 16-bit (0 … 65535), use DINT/LINT for larger signed values, UDINT/ULINT for larger unsigned values.
Special behavior: saturating arithmetic — overflow clamps to the maximum, underflow clamps to minimum (signed) or 0 (unsigned).
vb
PROGRAM
DIM a AS INT = 32760
DIM b AS INT = 100
PRINT a + b ' Output: 32767 (saturated, no overflow)
END PROGRAMPromotion rules: operations involving mixed types promote to the wider type
(INT + DINT → DINT, INT + REAL → REAL).
Floating Point (REAL/LREAL)
REAL = 32-bit, LREAL = 64-bit. IEEE 754 compliant. Suitable for physical values with decimals.
vb
PROGRAM
PRINT 7 / 2 ' Output: 3 (INT division)
PRINT TO_REAL(7) / 2 ' Output: 3.5 (REAL division)
END PROGRAMTip: If fractional results are required, convert first using TO_REAL.
BOOL & Comparisons
BOOL only supports TRUE and FALSE. Comparisons return BOOL. Operators: AND, OR, XOR, NOT.
vb
PROGRAM
DIM ok AS BOOL
ok = (5 < 7)
PRINT ok ' Output: TRUE
END PROGRAMTIME / DATE
TIME is stored in milliseconds. Syntax: T#500ms, T#2s, T#1h.
DATE, TOD, DT examples: DATE#2025-01-01, TOD#12:00:00, DT#2025-01-01-12:00:00.
vb
PROGRAM
PRINT TO_TIME(1000) ' Output: T#1000ms
PRINT ADD_TIME(T#500ms, T#200ms) ' Output: T#700ms
END PROGRAMTIME is often used together with blocks like TON.
Type Conversions
All TO_* functions are safety-oriented. Non-representable values are clamped instead of wrapping.
vb
PROGRAM
PRINT TO_UINT(-5) ' Output: 0
PRINT TO_INT(3.9) ' Output: 3
PRINT TO_REAL(42) ' Output: 42.0
END PROGRAMSummary
- Integers saturate; unsigned clamps to 0.
- Promotion raises operands to the wider type.
- REAL/LREAL for fractional values; INT division truncates.
- BOOL from comparisons and logical operators.
- TIME/DATE/DT enable time-based logic.
TO_*conversion functions are safe and deterministic.