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.
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.
absfunctionReturns an absolute integer magnitude.
invfunctionReturns the documented inverse form of a value.
isqrtfunctionComputes an integer square root.
powfunctionComputes an integer power within documented limits.
randomfunction · Zen onlyGenerates a value between the specified bounds.
set_bitfunctionSets one bit in a value.
clear_bitfunctionClears one bit in a value.
test_bitfunctionTests one bit in a value.
get_bitsfunctionExtracts a documented bit range.
set_bitsfunctionUpdates 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
Understand signed 16-bit runtime values, global storage, local scope, initialization, and safe array indexing.
LanguageGPC operators and control flowBuild conditions and loops with comparison, logical, arithmetic, assignment, if, else, while, for, break, and continue.
LanguageUser functions in GPCExtract reusable synchronous calculations while respecting parameter, return, recursion, and combo-only timing rules.