Beispiel #1
0
int
main (int argc, char *argv[])
{
  mpfr_t x, z;
  int y;
  int i;

  tests_start_mpfr ();
  mpfr_inits2 (53, x, z, (mpfr_ptr) 0);
  for(i = 0 ; i < numberof (tab) ; i++)
    {
      mpfr_set_str (x, tab[i].op1, 16, MPFR_RNDN);
      y = tab[i].op2;
      mpfr_add_si (z, x, y, MPFR_RNDZ);
      if (mpfr_cmp_str (z, tab[i].res_add, 16, MPFR_RNDN))
        ERROR1("add_si", i, z, tab[i].res_add);
      mpfr_sub_si (z, x, y, MPFR_RNDZ);
      if (mpfr_cmp_str (z, tab[i].res_sub, 16, MPFR_RNDN))
        ERROR1("sub_si", i, z, tab[i].res_sub);
      mpfr_si_sub (z, y, x, MPFR_RNDZ);
      mpfr_neg (z, z, MPFR_RNDZ);
      if (mpfr_cmp_str (z, tab[i].res_sub, 16, MPFR_RNDN))
        ERROR1("si_sub", i, z, tab[i].res_sub);
      mpfr_mul_si (z, x, y, MPFR_RNDZ);
      if (mpfr_cmp_str (z, tab[i].res_mul, 16, MPFR_RNDN))
        ERROR1("mul_si", i, z, tab[i].res_mul);
      mpfr_div_si (z, x, y, MPFR_RNDZ);
      if (mpfr_cmp_str (z, tab[i].res_div, 16, MPFR_RNDN))
        ERROR1("div_si", i, z, tab[i].res_div);
    }
  mpfr_set_str1 (x, "1");
  mpfr_si_div (z, 1024, x, MPFR_RNDN);
  if (mpfr_cmp_str1 (z, "1024"))
    ERROR1("si_div", i, z, "1024");
  mpfr_si_div (z, -1024, x, MPFR_RNDN);
  if (mpfr_cmp_str1 (z, "-1024"))
    ERROR1("si_div", i, z, "-1024");

  mpfr_clears (x, z, (mpfr_ptr) 0);

  check_invert ();

  test_generic_add_si (2, 200, 17);
  test_generic_sub_si (2, 200, 17);
  test_generic_mul_si (2, 200, 17);
  test_generic_div_si (2, 200, 17);

  tests_end_mpfr ();
  return 0;
}
Beispiel #2
0
static void
check_invert (void)
{
  mpfr_t x;
  mpfr_init2 (x, MPFR_PREC_MIN);

  mpfr_set_ui (x, 0xC, MPFR_RNDN);
  mpfr_si_sub (x, -1, x, MPFR_RNDD); /* -0001 - 1100 = - 1101 --> -1 0000 */
  if (mpfr_cmp_si (x, -0x10) )
    {
      printf ("Special rounding error\n");
      exit (1);
    }
  mpfr_clear (x);
}
Beispiel #3
0
static void
check_invert (void)
{
  mpfr_t x;
  mpfr_init2 (x, MPFR_PREC_MIN);

  mpfr_set_ui (x, 0xC, MPFR_RNDN);
  mpfr_si_sub (x, -1, x, MPFR_RNDD); /* -0001 - 1100 = - 1101 --> -1 0000 */
  /* If MPFR_PREC_MIN = 2, then x is first set to 12 exactly, then we get
     -13 which is rounded down to -16.
     If MPFR_PREC_MIN = 1, then x is first set to 16 exactly, then we get
     -17 which is rounded down to -32. */
  if ((MPFR_PREC_MIN == 2 && mpfr_cmp_si (x, -0x10)) ||
      (MPFR_PREC_MIN == 1 && mpfr_cmp_si (x, -0x20)))
    {
      printf ("Special rounding error\n");
      exit (1);
    }
  mpfr_clear (x);
}