k_tanf.c revision 176451
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 17176451Sdas#include <sys/cdefs.h> 18176451Sdas__FBSDID("$FreeBSD: head/lib/msun/src/k_tanf.c 176451 2008-02-22 02:30:36Z das $"); 192116Sjkh#endif 202116Sjkh 212116Sjkh#include "math.h" 222116Sjkh#include "math_private.h" 23152343Sbde 24152741Sbde/* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */ 25152713Sbdestatic const double 262116SjkhT[] = { 27152741Sbde 0x15554d3418c99f.0p-54, /* 0.333331395030791399758 */ 28152741Sbde 0x1112fd38999f72.0p-55, /* 0.133392002712976742718 */ 29152741Sbde 0x1b54c91d865afe.0p-57, /* 0.0533812378445670393523 */ 30152741Sbde 0x191df3908c33ce.0p-58, /* 0.0245283181166547278873 */ 31152741Sbde 0x185dadfcecf44e.0p-61, /* 0.00297435743359967304927 */ 32152741Sbde 0x1362b9bf971bcd.0p-59, /* 0.00946564784943673166728 */ 332116Sjkh}; 342116Sjkh 35152870Sbde#ifdef INLINE_KERNEL_TANDF 36152647Sbdeextern inline 37152647Sbde#endif 3897413Salfredfloat 39152713Sbde__kernel_tandf(double x, int iy) 402116Sjkh{ 41152881Sbde double z,r,w,s,t,u; 42152343Sbde 432116Sjkh z = x*x; 44152881Sbde /* 45152881Sbde * Split up the polynomial into small independent terms to give 46152881Sbde * opportunities for parallel evaluation. The chosen splitting is 47152881Sbde * micro-optimized for Athlons (XP, X64). It costs 2 multiplications 48152881Sbde * relative to Horner's method on sequential machines. 49152881Sbde * 50152881Sbde * We add the small terms from lowest degree up for efficiency on 51152881Sbde * non-sequential machines (the lowest degree terms tend to be ready 52152881Sbde * earlier). Apart from this, we don't care about order of 53152881Sbde * operations, and don't need to to care since we have precision to 54152881Sbde * spare. However, the chosen splitting is good for accuracy too, 55152881Sbde * and would give results as accurate as Horner's method if the 56152881Sbde * small terms were added from highest degree down. 57152881Sbde */ 58152881Sbde r = T[4]+z*T[5]; 59152881Sbde t = T[2]+z*T[3]; 60152881Sbde w = z*z; 612116Sjkh s = z*x; 62152881Sbde u = T[0]+z*T[1]; 63152881Sbde r = (x+s*u)+(s*w)*(t+w*r); 64152766Sbde if(iy==1) return r; 65152766Sbde else return -1.0/r; 662116Sjkh} 67