If you change this to double ang = min_theta; I believe this fixes the error.  You can also get rid of the cast of ang to double on line 112 and 113.