Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 1 | /* e_asinf.c -- float version of e_asin.c. |
| 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. |
| 3 | */ |
| 4 | |
| 5 | /* |
| 6 | * ==================================================== |
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
| 8 | * |
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
| 10 | * Permission to use, copy, modify, and distribute this |
| 11 | * software is freely granted, provided that this notice |
| 12 | * is preserved. |
| 13 | * ==================================================== |
| 14 | */ |
| 15 | |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 16 | #include "math.h" |
| 17 | #include "math_private.h" |
| 18 | |
| 19 | static const float |
| 20 | one = 1.0000000000e+00, /* 0x3F800000 */ |
Elliott Hughes | 8cca5d4 | 2024-08-29 20:28:45 +0000 | [diff] [blame] | 21 | huge = 1.000e+30; |
| 22 | |
| 23 | /* |
| 24 | * The coefficients for the rational approximation were generated over |
| 25 | * 0x1p-12f <= x <= 0.5f. The maximum error satisfies log2(e) < -30.084. |
| 26 | */ |
| 27 | static const float |
| 28 | pS0 = 1.66666672e-01f, /* 0x3e2aaaab */ |
| 29 | pS1 = -1.19510300e-01f, /* 0xbdf4c1d1 */ |
| 30 | pS2 = 5.47002675e-03f, /* 0x3bb33de9 */ |
| 31 | qS1 = -1.16706085e+00f, /* 0xbf956240 */ |
| 32 | qS2 = 2.90115148e-01f; /* 0x3e9489f9 */ |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 33 | |
| 34 | static const double |
| 35 | pio2 = 1.570796326794896558e+00; |
| 36 | |
| 37 | float |
Elliott Hughes | 4088e3a | 2023-08-03 13:33:56 -0700 | [diff] [blame] | 38 | asinf(float x) |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 39 | { |
| 40 | double s; |
| 41 | float t,w,p,q; |
| 42 | int32_t hx,ix; |
| 43 | GET_FLOAT_WORD(hx,x); |
| 44 | ix = hx&0x7fffffff; |
| 45 | if(ix>=0x3f800000) { /* |x| >= 1 */ |
| 46 | if(ix==0x3f800000) /* |x| == 1 */ |
| 47 | return x*pio2; /* asin(+-1) = +-pi/2 with inexact */ |
| 48 | return (x-x)/(x-x); /* asin(|x|>1) is NaN */ |
| 49 | } else if (ix<0x3f000000) { /* |x|<0.5 */ |
| 50 | if(ix<0x39800000) { /* |x| < 2**-12 */ |
| 51 | if(huge+x>one) return x;/* return x with inexact if x!=0*/ |
| 52 | } |
| 53 | t = x*x; |
| 54 | p = t*(pS0+t*(pS1+t*pS2)); |
Elliott Hughes | 8cca5d4 | 2024-08-29 20:28:45 +0000 | [diff] [blame] | 55 | q = one+t*(qS1+t*qS2); |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 56 | w = p/q; |
| 57 | return x+x*w; |
| 58 | } |
| 59 | /* 1> |x|>= 0.5 */ |
| 60 | w = one-fabsf(x); |
| 61 | t = w*(float)0.5; |
| 62 | p = t*(pS0+t*(pS1+t*pS2)); |
Elliott Hughes | 8cca5d4 | 2024-08-29 20:28:45 +0000 | [diff] [blame] | 63 | q = one+t*(qS1+t*qS2); |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 64 | s = sqrt(t); |
| 65 | w = p/q; |
| 66 | t = pio2-2.0*(s+s*w); |
| 67 | if(hx>0) return t; else return -t; |
| 68 | } |