[MLton-devel] Int-inf shifts

Stephen Weeks MLton@mlton.org
Thu, 31 Oct 2002 17:49:11 -0800


> (I figured
> I'd wait until after the merge and avoid bootstrapping problems; or, I
> guess I really shoul fill in the stubs.) 

Yeah, have to fill in the stubs (both in mlton-stubs and
mlton-stubs-in-smlnj), especially so others can compile a new MLton
with an older MLton.

> The basis says:
> 
>  ~>> (i, n)
>     shifts i to the right by n bit positions. When i and n are interpreted
> as integers, the latter non-negative, this returns Floor (i / 2(n)).

So, if I understand correctly

~>> (~5, 0w1) = Floor (~5 / 2) = Floor (~2.5) = ~3

In infinite twos-complement
	
~1 	...111111
~2	...111110
~3	...111101
~4	...111100
~5	...111011

so ~>> (~5, 0w1) = ~>> (...111011, 0w1) = ...111101 = ~3

OK it works.  :-)

> The A ~>> 12 would seem to clinch it -- a negative 2's complement integer
> has an infinite number of leading 1s, so a sufficiently high shift should
> yield an infinite word of all 1s, which interpreted in 2's complement
> would be ~1, not 0.

Agreed.  Put another way, i/(2^n) < 0 if i < 0, 
so Floor (i/(2^n)) <= ~1.


-------------------------------------------------------
This sf.net email is sponsored by: Influence the future 
of Java(TM) technology. Join the Java Community 
Process(SM) (JCP(SM)) program now. 
http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0004en
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel