[Mpc-discuss] MPC overflow handling in MPC_RNDZZ mode

Joseph Myers joseph at codesourcery.com
Wed Mar 25 19:53:15 CET 2015


Using MPC 1.0.3, the following program:

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

int
main (void)
{
  mpc_t a, b;

  mpc_init2 (a, 500);
  mpc_init2 (b, 500);
  mpc_set_str (a, "(-0x1p200 -0x1p800)", 0, MPC_RNDZZ);

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

  return 0;
}

prints:

(- at Inf@ @Inf@)

But when rounding to zero, overflow should never produce an infinity but 
the largest finite value with the appropriate sign; in that rounding mode, 
infinities should only be produced when exact.  If I do a similar 
massively overflowing case with mpfr_pow, for example, I properly get a 
finite rounded result with very large exponent.

I don't know what other MPC functions might be affected by this; mpc_cos 
is the first one I came across it with when putting such large values in 
glibc's generator of expected test results.

-- 
Joseph S. Myers
joseph at codesourcery.com


More information about the Mpc-discuss mailing list