Celestial Programming : Low Precision Formula for Sun Position

Algorithm from the Astronomical Almanac, page C5 (2017 ed). Accuracy 1deg from 1950-2050.

$$ \begin{align*} n&=jd-2451545.0 \\ L&=280.460+0.9856474n \\ g&=357.528+.9856003n \\ \lambda &=L+1.915 \sin g+0.020 \sin 2g \\ \beta&=0.0 \\ \epsilon &=23.439-0.0000004n \\ \cos\lambda \tan \alpha &=\cos\epsilon \sin\lambda \\ \sin \delta &=\sin\epsilon \sin \lambda \end{align*} $$ Where \(\lambda\) is the ecliptic longitude, \(\beta\) is the ecliptic latitude (always 0), \(\alpha\) is the Right Ascension, and \(\delta\) is the Declination.

Compute Geocentric RA/DEC of Sun.
JD:
RA: Hours
DEC: Degrees

//Low precision sun position from Astronomical Almanac page C5 (2017 ed).
//Accuracy 1deg from 1950-2050
function sunPosition(jd)	{
	const torad=Math.PI/180.0;
	n=jd-2451545.0;
	L=(280.460+0.9856474*n)%360;
	g=((357.528+.9856003*n)%360)*torad;
	if(L<0){L+=360;}
	if(g<0){g+=Math.PI*2.0;}

	lambda=(L+1.915*Math.sin(g)+0.020*Math.sin(2*g))*torad;
	beta=0.0;
	eps=(23.439-0.0000004*n)*torad;
	ra=Math.atan2(Math.cos(eps)*Math.sin(lambda),Math.cos(lambda));
	dec=Math.asin(Math.sin(eps)*Math.sin(lambda));
	if(ra<0){ra+=Math.PI*2;}
	return [ra/torad/15.0,dec/torad];
}