Binary "Shift Left" operator?

David Bovill david at openpartnership.net
Tue Apr 29 13:34:59 EDT 2008


2008/4/29 Colin Holgate <coiin at rcn.com>:

> At 5:23 PM +0100 4/29/08, David Bovill wrote:
>
> > Is there an equivalent in Rev - if not can anyone translate this to some
> > basic math functions?
> >
>
> Shift left is the same as * 2. 31 << 3 would be the same as * 8.
>
> What was it that you needed to achieve?
>

I'm making a start on the Map library as part of a suite of open source API
libraries. This JavaScript function is for a Mercator Projection used in
Google maps amongst others. The script looks like this:

function Adjust(x,y,deltaX,deltaY,z)
> {
> 	var offset=268435456;
> 	var radius=offset/Math.PI;
>
> 	function LToX(x)
> 	{
> 		return Math.round(offset+radius*x*Math.PI/180);
> 	}
>
> 	function LToY(y)
> 	{
> 		return Math.round(offset-radius*Math.log((1+Math.sin(y*Math.PI/180))/(1-Math.sin(y*Math.PI/180)))/2);
> 	}
>
> 	function XToL(x)
> 	{
> 		return ((Math.round(x)-offset)/radius)*180/Math.PI;
> 	}
>
> 	function YToL(y)
> 	{
> 		return (Math.PI/2-2*Math.atan(Math.exp((Math.round(y)-offset)/radius)))*180/Math.PI;
> 	}
>
> 	return {x:XToL(LToX(x)+(deltaX<<(21-z))),y:YToL(LToY(y)+(deltaY<<(21-z)))};
> }
>
>
And its the last line that looks tricky. The

> deltaX<<(21-z)
>
> is the bit I guess i am looking most to figure out?



More information about the Use-livecode mailing list