1 /* sincosf.c: Computes sin or cos of a 32-bit float as outlined in [1]
3 Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19 /* [1] William James Cody and W. M. Waite. _Software manual for the
20 elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */
22 /* Version 1.0 - Initial release */
27 #define r1 -0.1666665668E+0
28 #define r2 0.8333025139E-2
29 #define r3 -0.1980741872E-3
30 #define r4 0.2601903036E-5
34 #define C2 9.676535897E-4
36 /*A reasonable value for YMAX is the int part of PI*B**(t/2)=3.1416*2**(12)*/
39 float sincosf(const float x, const int iscos)
68 /*Round y/PI to the nearest integer*/
69 N=((y*iPI)+0.5); /*y is positive*/
71 /*If N is odd change sign*/
75 /*Cosine required? (is done here to keep accuracy)*/
81 f=((r-XN*C1)+g)-XN*C2;
84 if(g>EPS2) //Used to be if(fabsf(f)>EPS)
86 r=(((r4*g+r3)*g+r2)*g+r1)*g;