Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / device / lib / tancotf.c
blobd2e1d2cae745905a2ebc2f5e75fba1f404091e60
1 /*-------------------------------------------------------------------------
2 tancotf.c - Computes tan or cot 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 P0 0.100000000E+1
39 #define P1 -0.958017723E-1
40 #define Q0 0.100000000E+1
41 #define Q1 -0.429135777E+0
42 #define Q2 0.971685835E-2
44 #define C1 1.5703125
45 #define C2 4.83826794897E-4
47 #define P(f,g) (P1*g*f+f)
48 #define Q(g) ((Q2*g+Q1)*g+Q0)
50 //A reasonable choice for YMAX is the integer part of B**(t/2)*PI/2:
51 #define YMAX 6433.0
53 float tancotf(float x, bool iscotan)
55 float f, g, xn, xnum, xden;
56 int n;
58 if (fabsf(x) > YMAX)
60 errno = ERANGE;
61 return 0.0;
64 /*Round x*2*PI to the nearest integer*/
65 n=(x*TWO_O_PI+(x>0.0?0.5:-0.5)); /*works for +-x*/
66 xn=n;
68 xnum=(int)x;
69 xden=x-xnum;
70 f=((xnum-xn*C1)+xden)-xn*C2;
72 if (fabsf(f) < EPS)
74 xnum = f;
75 xden = 1.0;
77 else
79 g = f*f;
80 xnum = P(f,g);
81 xden = Q(g);
84 if(n&1)
85 //xn is odd
87 if(iscotan) return (-xnum/xden);
88 else return (-xden/xnum);
90 else
92 if(iscotan) return (xden/xnum);
93 else return (xnum/xden);