HELP INT                                    R. J. Duncan, September 1989

Functions on integers.


    CONTENTS - (Use <ENTER> g to access required sections)

 -- The Int Module
 -- Integer Functions


-- The Int Module -----------------------------------------------------

signature Int
structure Int : Int
    The structure -Int- is a  built-in structure of PML which  defines a
    collection of useful  functions on  integers. It  has the  following
    signature:

        signature Int = sig

            exception Power

            val sign    : int -> int
            val max     : int -> int -> int
            val min     : int -> int -> int
            val power   : int -> int -> int
            val gcd     : int -> int -> int
            val lcm     : int -> int -> int

            val **      : int * int -> int
            val quot    : int * int -> int
            val rem     : int * int -> int

        end

    For the definition of the integer type (int) see HELP * STDTYPES.
    For the basic mathematical operators see HELP * STDVALUES.
    For a similar set of functions on real numbers see HELP * REAL.


-- Integer Functions --------------------------------------------------

val sign (n : int) : int
    Returns the sign of the integer  -n-, i.e., one of the integers  ~1,
    0, or 1 according to whether -n-  is less than, equal to or  greater
    than zero.


val max (n1 : int) (n2 : int) : int
    Returns the greater of the integers -n1- and -n2-.


val min (n1 : int) (n2 : int) : int
    Returns the lesser of the integers -n1- and -n2-.


infix 7 quot rem
val (i : int) quot (d : int) : int
val (i : int) rem  (d : int) : int
    Integer division and remainder. Given

        val (q, r) = (i quot d, i rem d)

    then the relationship

        i = d * q + r

    holds, where abs(d * q) <= abs(i) (i.e. the division rounds  towards
    zero). For both -quot-  and -rem-, the  standard exception -Div-  is
    raised if -d- is zero.

    The functions -quot-  and -rem-  are typically  faster than  (though
    slightly different to) the standard integer division operators -div-
    and -mod- described in HELP * STDVALUES.


exception Power
infix 8 **
val (n : int) ** (m : int) : int
val power (n : int) (m : int) : int
    Returns the  value  of -n-  raised  to  the power  -m-.  Raises  the
    exception -Power- if -m- is less than zero. For a more general power
    function see HELP * REAL/power.


val gcd (n1 : int) (n2 : int) : int
    Returns the greatest common divisor of the integers -n1- and -n2-.


val lcm (n1 : int) (n2 : int) : int
    Returns the least common multiple of the integers -n1- and -n2-.


--- C.all/pml/help/int
--- Copyright University of Sussex 1991. All rights reserved. ----------
