Hide Forgot
Created attachment 551534 [details] tan(pi/2) eval requires too much time Description of problem: tan(x) evaluated at x = k*M_PI/2 where k=1,2,3,... or k=-1,-2,-3,... requires 2 orders of magnitude more time than in the other cases. Version-Release number of selected component (if applicable): gcc (GCC) 4.6.2 20111027 (Red Hat 4.6.2-1) glibc-2.14.90-24.fc16.4.x86_64 How reproducible: compiling and executing the attached source code Steps to Reproduce: 1. gcc -O2 tan-pi-div-2.c -lm 2. ./a.out > data.txt 3. gnuplot (plot "data.txt" using 1:2 with lines) Actual results: peaks at pi/2 multiples Expected results: all values in the same range Additional info: see attached file
This is the same as: http://sources.redhat.com/bugzilla/show_bug.cgi?id=3783 In a nutshell, glibc's tan implementation first computes the result using FPU instructions. if the maximum error is sufficiently low that result is returned. Obviously this is fast. If the error is potentially > than 0.5ulp, then glibc falls back to a more expensive algorithm to compute the result. For tan, values such as pi/2 multiples will trigger the need to use the slower algorithm, thus the significantly longer times.