LanguageUpdated 2026-07-24

Math and bit functions

Use the official integer math helpers and verified bit-field functions within GPC numeric limits.

Overview

GPC math operates in a signed 16-bit integer environment. The official math table lists abs, inv, pow, isqrt, and Zen-only random.

Bit functions are useful for flags and packed data, but bit positions and signed values require care.

Key facts

  • Standard GPC variables are signed 16-bit integers.
  • Function input and output ranges are function-specific.
  • Bit positions must be within the documented storage width.

GPC syntax examples

Examples are intentionally small. Replace identifiers only with values documented for your target.

Flag testexample.gpc
int flags;

main {
    if (test_bit(flags, 0)) {
        // flag zero is set
    }
}

Functions, commands, and terms

Names below are catalog entries, not guessed signatures. Open the official sources for current parameter and return-value details.

NameKindPurpose
absfunction

Returns an absolute integer magnitude.

invfunction

Returns the documented inverse form of a value.

isqrtfunction

Computes an integer square root.

powfunction

Computes an integer power within documented limits.

randomfunction · Zen only

Generates a value between the specified bounds.

set_bitfunction

Sets one bit in a value.

clear_bitfunction

Clears one bit in a value.

test_bitfunction

Tests one bit in a value.

get_bitsfunction

Extracts a documented bit range.

set_bitsfunction

Updates a documented bit range.

Common mistakes

Assuming floating-point behavior.

Copying trigonometric APIs from another GPC dialect.

Addressing a bit beyond the value's documented width.

Ignoring overflow in intermediate arithmetic.

Official GPC sources

Use these first-party references to confirm exact syntax and runtime behavior for your installed firmware and Studio version.

Related GPC references