4.27.1 Special purpose integer arithmetic
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Arithmetic
          • Special purpose integer arithmetic
            • between/3
            • succ/2
            • plus/3
            • divmod/4
            • nth_integer_root_and_remainder/4
    • Packages
Availability:built-in
divmod(+Dividend, +Divisor, -Quotient, -Remainder)
This predicate is a shorthand for computing both the Quotient and Remainder of two integers in a single operation. This allows for exploiting the fact that the low level implementation for computing the quotient also produces the remainder. Timing confirms that this predicate is almost twice as fast as performing the steps independently. Semantically, divmod/4 is defined as below.
divmod(Dividend, Divisor, Quotient, Remainder) :-
        Quotient  is Dividend div Divisor,
        Remainder is Dividend mod Divisor.

Note that this predicate is only available if SWI-Prolog is compiled with unbounded integer support. This is the case for all packaged versions.