[mercury-users] The Mercury random module

Warwick HARVEY warwick at cs.mu.oz.au
Sat Jul 5 03:14:53 AEST 1997


Fergus Henderson <fjh at cs.mu.OZ.AU> writes:
> This bug was in fact caused by using `mod' on a negative number.  In
> Mercury 0.6, the semantics of `mod' on negative numbers was not really
> well defined.  In our current development version, we have cleaned up
> the handling of integer division, modulus, and remainder for negative
> numbers.  The semantics of `mod' have been tightened up (it always
> returns a non-negative number), and there are new functions `div' and
> `rem'.  With this change, you can now choose between `//' (round-to-zero)
> and `div' (round-to-minus-infinity).  You call also choose between the
> corresponding remainders: `rem' is remainder with respect to `//', and
> `mod' is remainder with respect to `div'.

Yes!  Yes!  Woohoo!  *thunderous applause*  *paroxysms of delight*

It is SO annoying to have to work around unspecified rounding of integers
(when they may be negative) in languages like C.  This is the best news I've
heard all month (or week even! :-).

				Warwick

----------------------------------------------------------------------------
Warwick Harvey                                    email: warwick at cs.mu.OZ.AU
Department of Computer Science                        phone: +61-3-9344-9171
University of Melbourne                                 fax: +61-3-9348-1184
Parkville, Victoria, AUSTRALIA 3052     web: http://www.cs.mu.OZ.AU/~warwick



More information about the users mailing list