[Mpc-discuss] mpc_sin and mpc_sinh slow cases

Joseph S. Myers joseph at codesourcery.com
Fri Dec 20 00:59:20 CET 2013


mpc_sin is very slow in some cases of small inputs.  E.g.:

#include <stdio.h>
#include <mpc.h>
#include <mpfr.h>

int
main (void)
{
  mpc_t a, b;

  mpc_init2 (a, 115);
  mpc_init2 (b, 115);
  mpc_set_str (a, "(0x1p-16384 0x1p-16384)", 0, MPC_RNDNN);

  mpc_sin (b, a, MPC_RNDZZ);
  mpc_out_str (stdout, 10, 40, b, MPC_RNDNN);
  putc ('\n', stdout);

  return 0;
}

takes over 17 seconds for me (MPC 1.0.1).  mpc_sinh takes much the same 
time.  (Observed when trying to add these functions to glibc's generator 
of expected test results.  Even without the very slow functions, it's 
possible that profiling this generator would show up opportunities for 
speeding up MPC - about six out of seven seconds the generator takes with 
my latest patch are spent on complex rather than real functions.)

In such cases, where the result is very close to the input (closer than 
0.5ulp in whichever of the precisions of the result and the input is 
greater), computing a sufficient estimate of the difference between the 
result and the input (only its sign being needed) should be much quicker 
that repeatedly increasing the precision until the approximate result is 
good enough to determine the correctly rounded result.

-- 
Joseph S. Myers
joseph at codesourcery.com



More information about the Mpc-discuss mailing list