1a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes/* e_asinf.c -- float version of e_asin.c. 2a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes */ 4a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 5a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes/* 6a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * ==================================================== 7a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * 9a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * Developed at SunPro, a Sun Microsystems, Inc. business. 10a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * Permission to use, copy, modify, and distribute this 11a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * software is freely granted, provided that this notice 12a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * is preserved. 13a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes * ==================================================== 14a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes */ 15a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 16a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#include <sys/cdefs.h> 17a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes__FBSDID("$FreeBSD$"); 18a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 19a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#include "math.h" 20a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#include "math_private.h" 21a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 22a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughesstatic const float 23a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughesone = 1.0000000000e+00, /* 0x3F800000 */ 24a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hugheshuge = 1.000e+30, 25a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes /* coefficient for R(x^2) */ 26a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott HughespS0 = 1.6666586697e-01, 27a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott HughespS1 = -4.2743422091e-02, 28a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott HughespS2 = -8.6563630030e-03, 29a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott HughesqS1 = -7.0662963390e-01; 30a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 31a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughesstatic const double 32a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughespio2 = 1.570796326794896558e+00; 33a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 34a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughesfloat 35a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes__ieee754_asinf(float x) 36a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes{ 37a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes double s; 38a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes float t,w,p,q; 39a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes int32_t hx,ix; 40a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes GET_FLOAT_WORD(hx,x); 41a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes ix = hx&0x7fffffff; 42a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes if(ix>=0x3f800000) { /* |x| >= 1 */ 43a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes if(ix==0x3f800000) /* |x| == 1 */ 44a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes return x*pio2; /* asin(+-1) = +-pi/2 with inexact */ 45a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes return (x-x)/(x-x); /* asin(|x|>1) is NaN */ 46a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes } else if (ix<0x3f000000) { /* |x|<0.5 */ 47a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes if(ix<0x39800000) { /* |x| < 2**-12 */ 48a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes if(huge+x>one) return x;/* return x with inexact if x!=0*/ 49a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes } 50a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes t = x*x; 51a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes p = t*(pS0+t*(pS1+t*pS2)); 52a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes q = one+t*qS1; 53a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes w = p/q; 54a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes return x+x*w; 55a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes } 56a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes /* 1> |x|>= 0.5 */ 57a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes w = one-fabsf(x); 58a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes t = w*(float)0.5; 59a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes p = t*(pS0+t*(pS1+t*pS2)); 60a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes q = one+t*qS1; 61a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes s = sqrt(t); 62a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes w = p/q; 63a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes t = pio2-2.0*(s+s*w); 64a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes if(hx>0) return t; else return -t; 65a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes} 66