Appearance
Basic Functions
The basic functions are the fundamental toolset for all programs. They provide arithmetic operations, comparisons, logical operators, and type conversions. Unlike function blocks, these functions are stateless: they compute a result immediately and return it.
Mathematics
ABS(x): absolute value.
vb
PROGRAM
DIM v AS INT = -42
PRINT ABS(v) ' Output: 42
END PROGRAMSQRT(x): square root.
vb
PROGRAM
PRINT SQRT(9.0) ' Output: 3.0
END PROGRAMSIN(x), COS(x), TAN(x): trigonometric functions (radians).
vb
PROGRAM
PRINT SIN(3.14159/2) ' ≈ 1.0
PRINT COS(0.0) ' = 1.0
END PROGRAMEXP(x), LN(x), LOG(x), EXPT(x,y): exponential and logarithmic functions.
vb
PROGRAM
PRINT EXP(1.0) ' Output: 2.718...
PRINT LN(2.718) ' ≈ 1.0
PRINT LOG(100.0) ' Output: 2.0
PRINT EXPT(2.0, 3) ' Output: 8.0
END PROGRAMComparison & Logic
MAX(a,b), MIN(a,b): larger/smaller of two values.
vb
PROGRAM
PRINT MAX(3,7) ' Output: 7
PRINT MIN(3,7) ' Output: 3
END PROGRAMLIMIT(min,x,max): clamp value to interval.
vb
PROGRAM
DIM v AS INT = 120
PRINT LIMIT(0,v,100) ' Output: 100
END PROGRAMSEL(sel,a,b): select based on BOOL.
vb
PROGRAM
DIM useB AS BOOL = TRUE
PRINT SEL(useB, 10, 20) ' Output: 20
END PROGRAMLogical operators:
vb
PROGRAM
DIM a AS BOOL = TRUE
DIM b AS BOOL = FALSE
PRINT AND(a,b) ' Output: FALSE
PRINT OR(a,b) ' Output: TRUE
END PROGRAMConversions
TO_INT(x): integer conversion (truncate).
vb
PROGRAM
PRINT TO_INT(3.9) ' Output: 3
END PROGRAMTO_REAL(x): floating-point conversion.
vb
PROGRAM
PRINT TO_REAL(42) ' Output: 42.0
END PROGRAMTO_BOOL(x): 0 → FALSE, non‑zero → TRUE.
vb
PROGRAM
PRINT TO_BOOL(0) ' Output: FALSE
PRINT TO_BOOL(5) ' Output: TRUE
END PROGRAMTO_STRING(x): convert to string.
vb
PROGRAM
DIM v AS INT = 42
PRINT CONCAT("Value=", TO_STRING(v))
' Output: Value=42
END PROGRAMExercises with Solutions
Task 1: Compute absolute value of -42.
vb
PROGRAM
PRINT ABS(-42) ' Output: 42
END PROGRAMTask 2: Clamp a value to range 0‑100.
vb
PROGRAM
DIM v AS INT = 120
PRINT LIMIT(0,v,100) ' Output: 100
END PROGRAMTask 3: Convert number to string and print.
vb
PROGRAM
DIM v AS INT = 42
PRINT CONCAT("Value=", TO_STRING(v))
' Output: Value=42
END PROGRAMSummary
- Math functions cover basic arithmetic.
- Comparison & logic functions support safe decision‑making.
- Conversions are strict and saturating.
- All functions are deterministic and can be used directly in expressions.