Search                        Top                                  Index
HELP REM                                Revised by A.Sloman March 1987

<number> rem <number> -> <number>

REM is an infix operator (precedence 2) which returns the remainder when
one number divides another, e.g.

    10 rem 3 =>
    ** 1

    10 rem -3 =>
    ** 1

The result can be negative:

    -10 rem 3 =>
    ** -1

It could be defined thus:

    define 2 x rem y;
        lvars x,y;
        x // y ->
    enddefine;

Since "//" has been generalised to cope with non-integers, "rem" is also
no longer restricted to integers, e.g.

    99.5 rem 33.2 =>
    ** 33.1

    35_/8 rem 4 =>
    ** 3_/8

    10_+:1 rem 3 =>
    ** 1_+:1

REM used to be synonymous with MOD, but the latter has been redefined.
REM is guaranteed to produce a result with the same sign as its first
argument, MOD with the same sign as its second argument. So MOD and REM
can give different results for negative arguments:
See HELP * MOD for details.

REM has to check the types of its arguments. If you know that the
arguments will be integers you can use the fast_integer version: FI_REM
instead. For further details see HELP * EFFICIENCY and REF * FASTPROCS.

See also
REF * NUMBERS - for details of numbers and mathematical operations
    available in POP-11.
HELP * DIV  - division operator
HELP * MOD  - modulus operator
HELP * MATH - for a summary of mathematical operations in POP-11

-----<Copyright University of Sussex 1987.  All rights reserved.>-------