4.27.1 Special purpose integer arithmetic
All Application Manual Name SummaryHelp

  • 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
nth_integer_root_and_remainder(+N, +I, -Root, -Remainder)
True when Root ** N + Remainder = I. N and I must be integers.126This predicate was suggested by Markus Triska. The final name and argument order is by Richard O'Keefe. The decision to include the remainder is by Jan Wielemaker. Including the remainder makes this predicate about twice as slow if Root is not exact. N must be one or more. If I is negative and N is odd, Root and Remainder are negative, i.e., the following holds for I < 0:
%   I < 0,
%   N mod 2 =\= 0,
    nth_integer_root_and_remainder(
        N, I, Root, Remainder),
    IPos is -I,
    nth_integer_root_and_remainder(
        N, IPos, RootPos, RemainderPos),
    Root =:= -RootPos,
    Remainder =:= -RemainderPos.