[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

This page is part of the web mail archives of SRFI 77 from before July 7th, 2015. The new archives for SRFI 77 contain all messages, not just those from before July 7th, 2015.

*To*: Bradley Lucier <lucier@xxxxxxxxxxxxxxx>*Subject*: div and mod.*From*: bear <bear@xxxxxxxxx>*Date*: Tue, 21 Feb 2006 22:28:54 -0800 (PST)*Cc*: srfi-77@xxxxxxxxxxxxxxxxx*Delivered-to*: srfi-77@xxxxxxxxxxxxxxxxx*In-reply-to*: <55047DAD-A9BE-4F10-9287-8BEC3DD88440@xxxxxxxxxxxxxxx>*References*: <55047DAD-A9BE-4F10-9287-8BEC3DD88440@xxxxxxxxxxxxxxx>

For what it's worth, here is the behavior that I as a programmer expect from Div and Mod. I expect mod always to return a number between zero inclusive and the modulus exclusive. IOW, for all real X: (mod X 3) -> always a number between 0 and 3 (mod X -3) -> always a number between 0 and -3. I expect div to return whatever has to be returned to assure that for all real x and real N, (+ (mod x N) (* (div x N) N)) -> x It happens that in all cases where the signs match, the expected sign of the result of div is positive or zero. In all cases where the signs don't match, the expected sign of the result of div is negative or zero. In many systems they behave otherwise. When that happens, it frequently causes bugs which I eventually trace down to the application of div or modulus returning a negatve (or positive!) number unexpectedly, and after some experimentation kluge together a workaround or correction for. Bear

**Follow-Ups**:**Re: div and mod.***From:*Marcin 'Qrczak' Kowalczyk

**References**:**Questions about srfi-77 Generic Arithmetic***From:*Bradley Lucier

- Prev by Date:
**Re: Integer residue-classes [was: Questions about srfi-77 Generic Arithmetic]** - Next by Date:
**Re: Integer residue-classes** - Previous by thread:
**Re: Questions about srfi-77 Generic Arithmetic** - Next by thread:
**Re: div and mod.** - Index(es):