Here you can find the source of asin(double a)
Parameter | Description |
---|---|
a | the value whose arc sine is to be returned. |
public static double asin(double a)
//package com.java2s; /*//from w ww. ja v a2s. c o m * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This code is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * only, as published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 16 Network Circle, Menlo * Park, CA 94025 or visit www.sun.com if you need additional * information or have any questions. */ public class Main { private static final long no_sign_mask = 0x7FFFFFFFFFFFFFFFL; private static final long half = 0x3fe0000000000000L; private static final long high_bits_mask = 0xffffffff00000000L; private static final double pio2_hi = 1.57079632679489655800e+00; private static final double pio2_lo = 6.12323399573676603587e-17; private static final double pio4_hi = 7.85398163397448278999e-01; private static final double arc_pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ arc_pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ arc_pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ arc_pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ arc_pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ arc_pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ arc_qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ arc_qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ arc_qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ arc_qS4 = 7.70381505559019352791e-02; /** * Returns the arc sine of an angle, in the range of -<i>pi</i>/2 through <i>pi</i>/2. * Special cases: * <ul> * <li>If the argument is NaN or its absolute value is greater than 1, then the result is NaN. * <li>If the argument is zero, then the result is a zero with the same sign as the argument. * </ul> * * @param a the value whose arc sine is to be returned. * @return the arc sine of the argument. */ public static double asin(double a) { double t, w, p, q, c, r, s; long hx = Double.doubleToLongBits(a); long ix = hx & no_sign_mask; if (Math.abs(a) >= 1) { if (Math.abs(a) == 1) return (a * pio2_hi + a * pio2_lo); if (Math.abs(a) > 1) return (Double.NaN); } else if (ix < half) { /* |x| < 0.5 */ /* |x| < 2^-27 */ if (ix < 0x3e40000000000000L) { return (a); } else { t = a * a; p = t * (arc_pS0 + t * (arc_pS1 + t * (arc_pS2 + t * (arc_pS3 + t * (arc_pS4 + t * arc_pS5))))); q = 1.0 + t * (arc_qS1 + t * (arc_qS2 + t * (arc_qS3 + t * arc_qS4))); w = p / q; return (a + a * w); } } /* 1 > |x| > 0.5 */ w = 1.0 - Math.abs(a); t = w * 0.5; p = t * (arc_pS0 + t * (arc_pS1 + t * (arc_pS2 + t * (arc_pS3 + t * (arc_pS4 + t * arc_pS5))))); q = 1.0 + t * (arc_qS1 + t * (arc_qS2 + t * (arc_qS3 + t * arc_qS4))); s = Math.sqrt(t); /* if |x| >0.975 */ if (ix >= 0x3fef333300000000L) { w = p / q; t = pio2_hi - (2.0 * (s + s * w) - pio2_lo); } else { w = s; w = Double.longBitsToDouble(Double.doubleToLongBits(w) & high_bits_mask); c = (t - w * w) / (s + w); r = p / q; p = 2.0 * s * r - (pio2_lo - 2.0 * c); q = pio4_hi - 2.0 * w; t = pio4_hi - (p - q); } if (hx > 0) return (t); else return (-t); } }