blob: 8d1aca27df83d946cb0a659b3d7483aad7b3c55a [file] [log] [blame]
Elliott Hughesa0ee0782013-01-30 19:06:37 -08001/* 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 Hughesa0ee0782013-01-30 19:06:37 -080016#include "math.h"
17#include "math_private.h"
18
19static const float
20one = 1.0000000000e+00, /* 0x3F800000 */
Elliott Hughes8cca5d42024-08-29 20:28:45 +000021huge = 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 */
27static const float
28pS0 = 1.66666672e-01f, /* 0x3e2aaaab */
29pS1 = -1.19510300e-01f, /* 0xbdf4c1d1 */
30pS2 = 5.47002675e-03f, /* 0x3bb33de9 */
31qS1 = -1.16706085e+00f, /* 0xbf956240 */
32qS2 = 2.90115148e-01f; /* 0x3e9489f9 */
Elliott Hughesa0ee0782013-01-30 19:06:37 -080033
34static const double
35pio2 = 1.570796326794896558e+00;
36
37float
Elliott Hughes4088e3a2023-08-03 13:33:56 -070038asinf(float x)
Elliott Hughesa0ee0782013-01-30 19:06:37 -080039{
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 Hughes8cca5d42024-08-29 20:28:45 +000055 q = one+t*(qS1+t*qS2);
Elliott Hughesa0ee0782013-01-30 19:06:37 -080056 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 Hughes8cca5d42024-08-29 20:28:45 +000063 q = one+t*(qS1+t*qS2);
Elliott Hughesa0ee0782013-01-30 19:06:37 -080064 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}