1570af302Sopenharmony_ci/* origin: FreeBSD /usr/src/lib/msun/src/k_tanf.c */ 2570af302Sopenharmony_ci/* 3570af302Sopenharmony_ci * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 4570af302Sopenharmony_ci * Optimized by Bruce D. Evans. 5570af302Sopenharmony_ci */ 6570af302Sopenharmony_ci/* 7570af302Sopenharmony_ci * ==================================================== 8570af302Sopenharmony_ci * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. 9570af302Sopenharmony_ci * 10570af302Sopenharmony_ci * Permission to use, copy, modify, and distribute this 11570af302Sopenharmony_ci * software is freely granted, provided that this notice 12570af302Sopenharmony_ci * is preserved. 13570af302Sopenharmony_ci * ==================================================== 14570af302Sopenharmony_ci */ 15570af302Sopenharmony_ci 16570af302Sopenharmony_ci#include "libm.h" 17570af302Sopenharmony_ci 18570af302Sopenharmony_ci/* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */ 19570af302Sopenharmony_cistatic const double T[] = { 20570af302Sopenharmony_ci 0x15554d3418c99f.0p-54, /* 0.333331395030791399758 */ 21570af302Sopenharmony_ci 0x1112fd38999f72.0p-55, /* 0.133392002712976742718 */ 22570af302Sopenharmony_ci 0x1b54c91d865afe.0p-57, /* 0.0533812378445670393523 */ 23570af302Sopenharmony_ci 0x191df3908c33ce.0p-58, /* 0.0245283181166547278873 */ 24570af302Sopenharmony_ci 0x185dadfcecf44e.0p-61, /* 0.00297435743359967304927 */ 25570af302Sopenharmony_ci 0x1362b9bf971bcd.0p-59, /* 0.00946564784943673166728 */ 26570af302Sopenharmony_ci}; 27570af302Sopenharmony_ci 28570af302Sopenharmony_cifloat __tandf(double x, int odd) 29570af302Sopenharmony_ci{ 30570af302Sopenharmony_ci double_t z,r,w,s,t,u; 31570af302Sopenharmony_ci 32570af302Sopenharmony_ci z = x*x; 33570af302Sopenharmony_ci /* 34570af302Sopenharmony_ci * Split up the polynomial into small independent terms to give 35570af302Sopenharmony_ci * opportunities for parallel evaluation. The chosen splitting is 36570af302Sopenharmony_ci * micro-optimized for Athlons (XP, X64). It costs 2 multiplications 37570af302Sopenharmony_ci * relative to Horner's method on sequential machines. 38570af302Sopenharmony_ci * 39570af302Sopenharmony_ci * We add the small terms from lowest degree up for efficiency on 40570af302Sopenharmony_ci * non-sequential machines (the lowest degree terms tend to be ready 41570af302Sopenharmony_ci * earlier). Apart from this, we don't care about order of 42570af302Sopenharmony_ci * operations, and don't need to to care since we have precision to 43570af302Sopenharmony_ci * spare. However, the chosen splitting is good for accuracy too, 44570af302Sopenharmony_ci * and would give results as accurate as Horner's method if the 45570af302Sopenharmony_ci * small terms were added from highest degree down. 46570af302Sopenharmony_ci */ 47570af302Sopenharmony_ci r = T[4] + z*T[5]; 48570af302Sopenharmony_ci t = T[2] + z*T[3]; 49570af302Sopenharmony_ci w = z*z; 50570af302Sopenharmony_ci s = z*x; 51570af302Sopenharmony_ci u = T[0] + z*T[1]; 52570af302Sopenharmony_ci r = (x + s*u) + (s*w)*(t + w*r); 53570af302Sopenharmony_ci return odd ? -1.0/r : r; 54570af302Sopenharmony_ci} 55