Skip to content

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 PROGRAM

SQRT(x): square root.

vb
PROGRAM  
    PRINT SQRT(9.0) ' Output: 3.0  
END PROGRAM

SIN(x), COS(x), TAN(x): trigonometric functions (radians).

vb
PROGRAM  
    PRINT SIN(3.14159/2) ' ≈ 1.0  
    PRINT COS(0.0) ' = 1.0  
END PROGRAM

EXP(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 PROGRAM

Comparison & 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 PROGRAM

LIMIT(min,x,max): clamp value to interval.

vb
PROGRAM  
    DIM v AS INT = 120  
    PRINT LIMIT(0,v,100) ' Output: 100  
END PROGRAM

SEL(sel,a,b): select based on BOOL.

vb
PROGRAM  
    DIM useB AS BOOL = TRUE  
    PRINT SEL(useB, 10, 20) ' Output: 20  
END PROGRAM

Logical 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 PROGRAM

Conversions

TO_INT(x): integer conversion (truncate).

vb
PROGRAM  
    PRINT TO_INT(3.9) ' Output: 3  
END PROGRAM

TO_REAL(x): floating-point conversion.

vb
PROGRAM  
    PRINT TO_REAL(42) ' Output: 42.0  
END PROGRAM

TO_BOOL(x): 0 → FALSE, non‑zero → TRUE.

vb
PROGRAM  
    PRINT TO_BOOL(0) ' Output: FALSE  
    PRINT TO_BOOL(5) ' Output: TRUE  
END PROGRAM

TO_STRING(x): convert to string.

vb
PROGRAM  
    DIM v AS INT = 42  
    PRINT CONCAT("Value=", TO_STRING(v))  
    ' Output: Value=42  
END PROGRAM

Exercises with Solutions

Task 1: Compute absolute value of -42.

vb
PROGRAM  
    PRINT ABS(-42) ' Output: 42  
END PROGRAM

Task 2: Clamp a value to range 0‑100.

vb
PROGRAM  
    DIM v AS INT = 120  
    PRINT LIMIT(0,v,100) ' Output: 100  
END PROGRAM

Task 3: Convert number to string and print.

vb
PROGRAM  
    DIM v AS INT = 42  
    PRINT CONCAT("Value=", TO_STRING(v))  
    ' Output: Value=42  
END PROGRAM

Summary

  • 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.