Skip to content

sub operator

ffredyk edited this page Jul 23, 2026 · 1 revision

- (Subtraction / Negation)

Category

Arithmetic

Arity

Binaryleft - right (subtraction). Unary-value (negation prefix).

<number> - <number>    // binary: subtract
-<number>              // unary: negate

Description

Binary form: subtracts right operand from left operand. Returns the difference. Unary form: negates the operand (flips sign). Returns the negated value.

Auto-unwraps shared values before operating.

How It Works

The host re-registers - with enhanced behavior that unwraps shared values. Both forms ultimately perform double arithmetic. The compiler distinguishes unary from binary form by operand count.

Unary negation: -5 → compiled as nular 5 then unary - opcode.

Usage

Binary subtraction

_result = 10 - 3;             // 7
_damage = _incoming - _armor;
_remaining = _max - _current;

Unary negation

_x = -5;                      // -5
_vel = -_speed;               // negate variable
_delta = -(_a - _b);          // negate expression

With shared values

shared _count = 10;
_new = get _count - 3;        // auto-unwraps

Thread Safety

Not atomic on shared values — use sub for atomic decrement. Regular subtraction on primitives is thread-safe.

See Also

  • + — addition
  • * — multiplication
  • / — division
  • sub — atomic subtract for shared
  • abs — absolute value

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally