[M3devel] div/mod

Rodney M. Bates rodney_bates at lcwb.coop
Mon Jul 19 00:41:43 CEST 2010



Jay K wrote:
> ok, this is a really minor thing. Very esoteric, waste of time probably.
> 
> 
> Div and mod are defined in terms of each other.
> 
> 
> In the "real world", any integer mod negative 1 is 0. 
>   All integers are "evenly divisible" by 1 and negative 1.
> 
> So INT_MIN mod -1 is 0.
> 
> 
> One can code that to be the case. Some versions of the code do.
>   I'm not sure about the current code, as we don't call the C functions any longer, except for int64 on NT386.
>   The older div/mod helpers, depending on optimization, would either return 0
>    or generate an overflow exception.
> 
> 
> In our computer world, INT_MIN div -1 is not computable, and generates
>   the same exception. Even with current code.

My view of this is that the only reason INT_MIN DIV -1 raises an exception
is that the mathematical result is not in INTEGER.  The definitions of
all the arithmetic operators in the language should be viewed as using the
(unlimited range) operations of mathematics, with overflow happening
if this lies outside the range of the result type.  In fact, I doubt you
can sensibly interpret the definitions in the language any other way.

So it makes perfect sense for the DIV to raise the exception and the
MOD not, since 0 is indeed in INTEGER.


> 
> 
> If div and mod are defined in terms of each other, and one of them is not computable,
>   is it wrong to be able to compute the other?
> 
> 
>  - Jay
> 
>  		 	   		  



More information about the M3devel mailing list