k_tanf.c revision 152881
12116Sjkh/* k_tanf.c -- float version of k_tan.c
22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3152870Sbde * Optimized by Bruce D. Evans.
42116Sjkh */
52116Sjkh
62116Sjkh/*
72116Sjkh * ====================================================
8129981Sdas * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
92116Sjkh *
102116Sjkh * Permission to use, copy, modify, and distribute this
118870Srgrimes * software is freely granted, provided that this notice
122116Sjkh * is preserved.
132116Sjkh * ====================================================
142116Sjkh */
152116Sjkh
16152870Sbde#ifndef INLINE_KERNEL_TANDF
172116Sjkh#ifndef lint
1850476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/k_tanf.c 152881 2005-11-28 11:46:20Z bde $";
192116Sjkh#endif
20152647Sbde#endif
212116Sjkh
222116Sjkh#include "math.h"
232116Sjkh#include "math_private.h"
24152343Sbde
25152741Sbde/* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */
26152713Sbdestatic const double
272116SjkhT[] =  {
28152741Sbde  0x15554d3418c99f.0p-54,	/* 0.333331395030791399758 */
29152741Sbde  0x1112fd38999f72.0p-55,	/* 0.133392002712976742718 */
30152741Sbde  0x1b54c91d865afe.0p-57,	/* 0.0533812378445670393523 */
31152741Sbde  0x191df3908c33ce.0p-58,	/* 0.0245283181166547278873 */
32152741Sbde  0x185dadfcecf44e.0p-61,	/* 0.00297435743359967304927 */
33152741Sbde  0x1362b9bf971bcd.0p-59,	/* 0.00946564784943673166728 */
342116Sjkh};
352116Sjkh
36152870Sbde#ifdef INLINE_KERNEL_TANDF
37152647Sbdeextern inline
38152647Sbde#endif
3997413Salfredfloat
40152713Sbde__kernel_tandf(double x, int iy)
412116Sjkh{
42152881Sbde	double z,r,w,s,t,u;
43152343Sbde
442116Sjkh	z	=  x*x;
45152881Sbde	/*
46152881Sbde	 * Split up the polynomial into small independent terms to give
47152881Sbde	 * opportunities for parallel evaluation.  The chosen splitting is
48152881Sbde	 * micro-optimized for Athlons (XP, X64).  It costs 2 multiplications
49152881Sbde	 * relative to Horner's method on sequential machines.
50152881Sbde	 *
51152881Sbde	 * We add the small terms from lowest degree up for efficiency on
52152881Sbde	 * non-sequential machines (the lowest degree terms tend to be ready
53152881Sbde	 * earlier).  Apart from this, we don't care about order of
54152881Sbde	 * operations, and don't need to to care since we have precision to
55152881Sbde	 * spare.  However, the chosen splitting is good for accuracy too,
56152881Sbde	 * and would give results as accurate as Horner's method if the
57152881Sbde	 * small terms were added from highest degree down.
58152881Sbde	 */
59152881Sbde	r = T[4]+z*T[5];
60152881Sbde	t = T[2]+z*T[3];
61152881Sbde	w = z*z;
622116Sjkh	s = z*x;
63152881Sbde	u = T[0]+z*T[1];
64152881Sbde	r = (x+s*u)+(s*w)*(t+w*r);
65152766Sbde	if(iy==1) return r;
66152766Sbde	else return -1.0/r;
672116Sjkh}
68