Skip to main content

Operators

Operators are special symbols used to perform calculations, compare values, and evaluate expressions in TinyPanda.

Arithmetic Operators

TinyPanda supports standard mathematical operators for performing calculations on integers. It correctly respects operator precedence (multiplication and division are evaluated before addition and subtraction).

OperatorOperationExampleResult
+Addition5 + 510
-Subtraction10 - 37
*Multiplication4 * 28
/Division10 / 25
%Mod10 % 31

Zero Division Safety

Attempting to divide or mod by 0 or 0.0 will throw a runtime error instead of crashing the program.

echoln(10 / 0); // Runtime Error: cannot divide by zero
echoln(10.5 % 0); // Runtime Error: cannot divide by zero
Auto Type Cast
  • Integer Math: Performing division / or mod % on two INT operands always executes integer math and returns a INT value.
what(10 % 2); // Returns: INTEGER
  • Float Cast: If any operand in the expression is a FLOAT, the other operand is also casted to FLOAT type, and it always returns a FLOAT value, even if the final mathematical result is a INT value.
what(10 % 2.5); // Returns: FLOAT

what(<ident>) is a builtin function which returns the data type of the ident, learn nore about it here.

Increment and Decrement Operators

TinyPanda supports postfix increment (++) and postfix decrement (--) operators. These operators provide a clean, shortcut syntax to mutate existing numerical variables in place by adding or subtracting by 1.

Only INTEGER and FLOAT can be incremented or decremented.

bamboo num = 10;
num++;
echoln(num); // Outputs: 11
INFO

In TinyPanda, ++ and -- are statements, not expressions. This means they mutate the variable but do not return a value. You cannot assign them to other variables or pass them into function.

bamboo x = i++; // This is a imvalid syntax

Comparison Operators

Comparison operators look at two values and evaluate down to a boolean literal (true or false). These are highly useful for controlling flow inside conditional blocks.

OperatorDescriptionExampleResult
==Equal to5 == 5true
!=Not equal to5 != 3true
>Greater than10 > 2true
<Less than4 < 1false
>=Greater than or equal to5 >= 5true
<=Less than or equal to3 <= 5true
echoln(10 > 5); // Outputs: true
echoln(10 == 5); // Outputs: false

Prefix Operators

Prefix operators are placed before a single value to invert it or change its state. TinyPanda supports the ! (bang/exclamation) operator to invert boolean values.

OperatorDescriptionExampleResult
!Invert / NOT!falsetrue
echoln(!"name"); // Outputs: false
echoln(!1); // Outputs: false
echoln(!true); // Outputs: false
echoln(!false); // Outputs: true

You can learn about truthy and falsy values in TinyPanda here.

info

TinyPanda checks your data type on the left and right side of an operator. Operations or comparisons can only be performed if the data types on both sides matches.

Mixing mismatched types across an operator will instantly halt execution with a runtime error.

// Both of these will throw a runtime error!
iff (10 > "abc") { ... }
bamboo foo = "bar" + 100;