Prepare for SDCC 4.5.0 release.
[sdcc.git] / sdcc / device / lib / asincosf.c
blob9116e075cfd2837436af4122e2d14f3e56875b12
1 /*-------------------------------------------------------------------------
2 asincosf.c - Computes asin or acos of a 32-bit float as outlined in [1]
4 Copyright (C) 2001, 2002, Jesus Calvino-Fraga, jesusc@ieee.org
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19 MA 02110-1301, USA.
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
29 /* [1] William James Cody and W. M. Waite. _Software manual for the
30 elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */
32 /* Version 1.0 - Initial release */
34 #include <math.h>
35 #include <errno.h>
36 #include <stdbool.h>
38 #define P1 0.933935835E+0
39 #define P2 -0.504400557E+0
40 #define Q0 0.560363004E+1
41 #define Q1 -0.554846723E+1
42 #define Q2 0.100000000E+1
44 #define P(g) (P2 * g + P1)
45 #define Q(g) ((Q2 * g + Q1) * g + Q0)
47 float asincosf(float x, bool isacos)
49 float y, g, r;
50 unsigned char i;
51 bool quartPI = isacos;
53 static const float a[2] = { 0.0, QUART_PI };
54 static const float b[2] = { HALF_PI, QUART_PI };
56 y = fabsf(x);
57 if (y < EPS)
59 r = y;
61 else
63 if (y > 0.5)
65 quartPI = !isacos;
66 if (y > 1.0)
68 errno = EDOM;
69 return 0.0;
71 g = (0.5 - y) + 0.5;
72 g = ldexpf(g, -1);
73 y = sqrtf(g);
74 y = -(y + y);
76 else
78 g = y * y;
80 r = y + y * ((P(g) * g) / Q(g));
82 i = quartPI;
83 if (isacos)
85 if (x < 0.0)
86 r = (b[i] + r) + b[i];
87 else
88 r = (a[i] - r) + a[i];
90 else
92 r = (a[i] + r) + a[i];
93 if (x < 0.0)
94 r = -r;
96 return r;