Java atan atan(float x)

Here you can find the source of atan(float x)

Description

Arctan

License

Open Source License

Parameter

Parameter Description
x value to find arc tan for

Return

arctan x

Declaration

public static float atan(float x) 

Method Source Code

//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;
    }
}

Related

  1. atan(double a)
  2. atan(double arg)
  3. atan(double x)
  4. atan(float tan_value)
  5. atan(float value)
  6. atan(int f)
  7. atan(Integer a)
  8. atan(Number x)
  9. atan_66s(double x)