Skip to content
ffredyk edited this page Jul 23, 2026 · 1 revision

% (Modulo)

Category

Arithmetic

Arity

Binary — left operand % right operand.

<number> % <number>

Description

Returns the remainder after dividing the left operand by the right operand. Auto-unwraps shared values before operating.

Modulo by zero throws SqTypeError.

How It Works

Performs double floating-point modulo via a % b = a - b * floor(a / b). This matches C# % behavior for doubles, not truncated integer remainder. The host checks for zero divisor.

Usage

Basic modulo

_result = 10 % 3;             // 1
_remainder = 17 % 5;          // 2
_isEven = (_num % 2) == 0;

Wrap-around / cycling

_index = (_index + 1) % _arrayCount;  // wrap index
_angle = _angle % 360;                // normalize angle

Periodic checks

// Run every 5th frame
if (_frame % 5 == 0) then {
    doPeriodicWork();
};

Errors

  • SqTypeError — thrown when divisor is 0.

Thread Safety

Not atomic. Regular modulo on primitives is thread-safe.

See Also

  • / — division
  • floor — floor rounding
  • round — nearest integer

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