Here you can find the source of atan(float x)
Parameter | Description |
---|---|
x | value to find arc tan for |
public static float atan(float x)
//package com.java2s; public class Main { public final static float SQRT3 = 1.732050807568877294f; /**//from www . ja v a 2 s . c o m * Arctan * * @param x value to find arc tan for * @return arctan x */ public static float atan(float x) { boolean signChange = false; boolean Invert = false; int sp = 0; float x2, a; // check the sign change if (x < 0.) { x = -x; signChange = true; } // check the invertation if (x > 1.) { x = 1 / x; Invert = true; } // process shrinking domain until x<PI/12 while (x > (float) Math.PI / 12) { sp++; a = x + SQRT3; a = 1 / a; x = x * SQRT3; x = x - 1; x = x * a; } // calculation core x2 = x * x; a = x2 + 1.4087812f; a = 0.55913709f / a; a = a + 0.60310579f; a = a - (x2 * 0.05160454f); a = a * x; // process until sp=0 while (sp > 0) { a = a + (float) Math.PI / 6; sp--; } // invert if (Invert) a = (float) Math.PI / 2 - a; // sign change if (signChange) a = -a; // return a; } }