Here you can find the source of atan2(double y, double x)
public static final double atan2(double y, double x)
//package com.java2s; public class Main { public static final double atan2(double y, double x) { double atn = atan(y / x); if (y >= 0) { if (x >= 0) return atn; return Math.PI + atn; }//from w w w . j av a 2 s. c om if (x >= 0) { return atn; } return -Math.PI + atn; } /** returns [-PI/2, PI/2] accurate within 0.014 degrees **/ public static final double atan(double x) { if (Math.abs(x) <= 1) return atan_mag1(x); if (x < 0) return -Math.PI / 2 - atan_mag1(1 / x); else return Math.PI / 2 - atan_mag1(1 / x); } protected static final double atan_mag1(double x) { // accuracy = 0.26814 degrees // return x/(1+0.28087207802773*x*x); if (true) { if (Math.abs(x) > 1) System.out.printf("ATAN_MAG1: %15f\n", x); final double p0 = -0.000158023363661; final double p1 = 1.003839939589617; final double p2 = -0.016224975245612; final double p3 = -0.343317496147292; final double p4 = 0.141501628812858; double a = Math.abs(x); double a2 = a * a; double y = p0 + p1 * a + p2 * a2 + p3 * (a2 * a) + p4 * (a2 * a2); if (x < 0) return -y; return y; } else { double xx = x * x; // accuracy = 0.10550 degrees (according to matlab) return (0.00182789418543 + 0.97687229491851 * x + 0.00087659977713 * xx) / (0.99499024627366 + 0.00228262896304 * x + 0.25288677429562 * xx); } } }