# VBForums CodeBank > CodeBank - JavaScript >  [JAVASCRIPT] - Atan2

## XRsTX

Yes I know you can use:

Math.atan2(y,x), but I created this awhile ago when I was first starting and thought maybe someone would like it:



```
	function Atan2(y,x)
	 {
	  var theta = new Number();
		 var str = new String();
		 if (String.fromCharCode(x) < 0.0000001)
		  {
			if (String.fromCharCode(y) < 0.0000001)
			 {
			  theta = 0;
			 }
			 else if (y > 0)
			  {
				 theta = 1.5707963267949;
				}
			 else
			  {
				 theta = -1.5707963267949;
				}
			}
		 theta = Math.atan(y / x)
		  if (x < 0)
			 {
			 if (y >= 0)
			  {
				 theta = 3.14159265358979 + theta;
				}
				 else
				{
				 theta = theta - 3.14159265358979;
				}
			 }
		 return theta;
	 }
```

----------

