INTDIV(3am) GNU Awk Extension Modules INTDIV(3am)

intdiv - perform integer division in one operation

@load "intdiv"

success = intdiv(numerator, denominator, result)

The intdiv extension provides a single function that performs integer division, similar to the standard C div() function.

First, truncate numerator and denominator towards zero, creating integer values. Clear the result array, and then set result["quotient"] to the result of numerator / denominator, truncated towards zero to an integer, and set result["remainder"] to the result of numerator % denominator, truncated towards zero to an integer. Attempting division by zero causes a fatal error. The function returns zero upon success, and -1 upon error.

This function is useful primarily with GMP arbitrary length integers; it avoids creating MPFR arbitrary precision floating-point values.

GAWK: Effective AWK Programming, and the man pages for the other extensions shipped with gawk.

div(3).

Arnold Robbins, arnold@skeeve.com.

Copyright © 2026, Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies of this manual page provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual page under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual page into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.

Apr 15 2026 Free Software Foundation