Java asin asin(float x)

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

Description

Arcsin

License

Open Source License

Parameter

Parameter Description
x x value to find arc sin for

Return

arcsin of x

Declaration

public static float asin(float x) 

Method Source Code

//package com.java2s;

public class Main {
    public final static float SQRT3 = 1.732050807568877294f;

    /**/*from  ww  w  .jav a2  s  . co m*/
     * Arcsin
     *
     * @return arcsin of x
     * @param x x value to find arc sin for
     */
    public static float asin(float x) {
        if (x < -1. || x > 1.)
            return Float.NaN;
        if (x == -1.)
            return (float) -Math.PI / 2;
        if (x == 1)
            return (float) Math.PI / 2;
        return atan(x / (float) Math.sqrt(1 - x * x));
    }

    /**
     * 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. asin(double a)
  2. asin(double a)
  3. asin(double arg)
  4. asin(final double x)
  5. asin(float value)
  6. asin(int f)
  7. asin(Integer a)
  8. asin(Number x)
  9. asin_core(double x)