13a8617a8SJordan K. Hubbard /* k_tanf.c -- float version of k_tan.c 23a8617a8SJordan K. Hubbard * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3960d3da0SBruce Evans * Optimized by Bruce D. Evans. 43a8617a8SJordan K. Hubbard */ 53a8617a8SJordan K. Hubbard 63a8617a8SJordan K. Hubbard /* 73a8617a8SJordan K. Hubbard * ==================================================== 873fbb89dSDavid Schultz * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. 93a8617a8SJordan K. Hubbard * 103a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this 113a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice 123a8617a8SJordan K. Hubbard * is preserved. 133a8617a8SJordan K. Hubbard * ==================================================== 143a8617a8SJordan K. Hubbard */ 153a8617a8SJordan K. Hubbard 16960d3da0SBruce Evans #ifndef INLINE_KERNEL_TANDF 175aa554c7SDavid Schultz #include <sys/cdefs.h> 185aa554c7SDavid Schultz __FBSDID("$FreeBSD$"); 194ce51209SBruce Evans #endif 203a8617a8SJordan K. Hubbard 213a8617a8SJordan K. Hubbard #include "math.h" 223a8617a8SJordan K. Hubbard #include "math_private.h" 23e96c4fd9SBruce Evans 2416638b55SBruce Evans /* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */ 2594a5f9beSBruce Evans static const double 263a8617a8SJordan K. Hubbard T[] = { 2716638b55SBruce Evans 0x15554d3418c99f.0p-54, /* 0.333331395030791399758 */ 2816638b55SBruce Evans 0x1112fd38999f72.0p-55, /* 0.133392002712976742718 */ 2916638b55SBruce Evans 0x1b54c91d865afe.0p-57, /* 0.0533812378445670393523 */ 3016638b55SBruce Evans 0x191df3908c33ce.0p-58, /* 0.0245283181166547278873 */ 3116638b55SBruce Evans 0x185dadfcecf44e.0p-61, /* 0.00297435743359967304927 */ 3216638b55SBruce Evans 0x1362b9bf971bcd.0p-59, /* 0.00946564784943673166728 */ 333a8617a8SJordan K. Hubbard }; 343a8617a8SJordan K. Hubbard 35*2b795b29SDimitry Andric #ifdef INLINE_KERNEL_TANDF 36*2b795b29SDimitry Andric static __inline 374ce51209SBruce Evans #endif 38*2b795b29SDimitry Andric float 3994a5f9beSBruce Evans __kernel_tandf(double x, int iy) 403a8617a8SJordan K. Hubbard { 411dd21062SBruce Evans double z,r,w,s,t,u; 42e96c4fd9SBruce Evans 433a8617a8SJordan K. Hubbard z = x*x; 441dd21062SBruce Evans /* 451dd21062SBruce Evans * Split up the polynomial into small independent terms to give 461dd21062SBruce Evans * opportunities for parallel evaluation. The chosen splitting is 471dd21062SBruce Evans * micro-optimized for Athlons (XP, X64). It costs 2 multiplications 481dd21062SBruce Evans * relative to Horner's method on sequential machines. 491dd21062SBruce Evans * 501dd21062SBruce Evans * We add the small terms from lowest degree up for efficiency on 511dd21062SBruce Evans * non-sequential machines (the lowest degree terms tend to be ready 521dd21062SBruce Evans * earlier). Apart from this, we don't care about order of 531dd21062SBruce Evans * operations, and don't need to to care since we have precision to 541dd21062SBruce Evans * spare. However, the chosen splitting is good for accuracy too, 551dd21062SBruce Evans * and would give results as accurate as Horner's method if the 561dd21062SBruce Evans * small terms were added from highest degree down. 573a8617a8SJordan K. Hubbard */ 581dd21062SBruce Evans r = T[4]+z*T[5]; 591dd21062SBruce Evans t = T[2]+z*T[3]; 601dd21062SBruce Evans w = z*z; 613a8617a8SJordan K. Hubbard s = z*x; 621dd21062SBruce Evans u = T[0]+z*T[1]; 631dd21062SBruce Evans r = (x+s*u)+(s*w)*(t+w*r); 64833f0e1aSBruce Evans if(iy==1) return r; 65833f0e1aSBruce Evans else return -1.0/r; 663a8617a8SJordan K. Hubbard } 67