[m-dev.] Re: [mercury-users] abstract types.

Juergen Stuber juergen at mpi-sb.mpg.de
Wed Jan 19 01:03:19 AEDT 2000


Peter Schachte <schachte at cs.mu.OZ.AU> writes:
> 
> I've just submitted a new predicate for the int library module:
> 
> 	% code(Factor, Value, Residue, Coding)
> 	% holds iff Factor*Value+Residue = Coding, and 0 <= Value < Factor.w
> 	% This is useful for things like converting between time as 
> 	% hours, minutes, and seconds, and raw seconds.
> 
> :- pred code(int, int, int, int).
> :- mode code(in, in, in, out) is det.
> :- mode code(in, out, out, in) is det.

The name code is a bit unspecific IMHO.  Why don't you call
it divmod, since it is division with remainder backwards:

 	% divmod(Value, Divisor, Quotient, Residue)
 	% holds iff Value = Divisor*Quotient+Residue and 0 <= Residue < Divisor

:- pred divmod(int, int, int, int).
:- mode divmod(in, in, out, out) is det.
:- mode divmod(out, in, in, in) is det.

It is also useful to have a combined div and mod, since division
algorithms tend to produce quotient and residue simultaneously,
and calling div and mod separately executes them twice.

J|rgen

-- 
J|rgen Stuber <juergen at mpi-sb.mpg.de>
http://www.mpi-sb.mpg.de/~juergen/
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list