Exemplo n.º 1
0
static void
test1 (void)
{
  mpfr_ptr x, y;

  reset_stack ();
  org = (long *) stack;

  x = new_mpfr (p);
  y = new_mpfr (p);
  mpfr_set_ui (x, 42, MPFR_RNDN);
  mpfr_set_ui (y, 17, MPFR_RNDN);
  mpfr_add (y, x, y, MPFR_RNDN);
  y = return_mpfr (y, (char *) org);
  if ((long *) y != org || mpfr_cmp_ui (y, 59) != 0)
    {
      printf ("Compact (1) failed!\n");
      exit (1);
    }

  x = new_mpfr (p);
  y = new_mpfr (p);
  mpfr_set_ui (x, 4217, MPFR_RNDN);
  mpfr_set_ui (y, 1742, MPFR_RNDN);
  mpfr_add (y, x, y, MPFR_RNDN);
  y = return_mpfr_func (y, (char *) org);
  if ((long *) y != org || mpfr_cmp_ui (y, 5959) != 0)
    {
      printf ("Compact (5) failed!\n");
      exit (1);
    }

  reset_stack ();
}
Exemplo n.º 2
0
static void
test_nan_inf_zero (void)
{
  mpfr_ptr val;
  int sign;
  int kind;

  reset_stack ();

  val = new_mpfr (MPFR_PREC_MIN);
  mpfr_set_nan (val);
  kind = (mpfr_custom_get_kind) (val);
  if (kind != MPFR_NAN_KIND)
    {
      printf ("mpfr_custom_get_kind error: ");
      mpfr_dump (val);
      printf (" is kind %d instead of %d\n", kind, (int) MPFR_NAN_KIND);
      exit (1);
    }

  val = new_nan (MPFR_PREC_MIN);
  if (!mpfr_nan_p(val))
    {
      printf ("Error: mpfr_custom_init_set doesn't set NAN mpfr.\n");
      exit (1);
    }

  val = new_inf (MPFR_PREC_MIN);
  if (!mpfr_inf_p(val) || mpfr_sgn(val) >= 0)
    {
      printf ("Error: mpfr_custom_init_set doesn't set -INF mpfr.\n");
      exit (1);
    }

  sign = 1;
  mpfr_set_inf (val, sign);
  kind = (mpfr_custom_get_kind) (val);
  if ((ABS (kind) != MPFR_INF_KIND) || (SIGN (kind) != SIGN (sign)))
    {
      printf ("mpfr_custom_get_kind error: ");
      mpfr_dump (val);
      printf (" is kind %d instead of %d\n", kind, (int) MPFR_INF_KIND);
      printf (" have sign %d instead of %d\n", SIGN (kind), SIGN (sign));
      exit (1);
    }

  sign = -1;
  mpfr_set_zero (val, sign);
  kind = (mpfr_custom_get_kind) (val);
  if ((ABS (kind) != MPFR_ZERO_KIND) || (SIGN (kind) != SIGN (sign)))
    {
      printf ("mpfr_custom_get_kind error: ");
      mpfr_dump (val);
      printf (" is kind %d instead of %d\n", kind, (int) MPFR_ZERO_KIND);
      printf (" have sign %d instead of %d\n", SIGN (kind), SIGN (sign));
      exit (1);
    }

  reset_stack ();
}
Exemplo n.º 3
0
static void
test1 (void)
{
  mpfr_ptr x, y;
  char *org;

  org = stack;
  x = new_mpfr (p);
  y = new_mpfr (p);
  mpfr_set_ui (x, 42, MPFR_RNDN);
  mpfr_set_ui (y, 17, MPFR_RNDN);
  mpfr_add (y, x, y, MPFR_RNDN);
  y = return_mpfr (y, org);
  if (y != x || mpfr_cmp_ui (y, 59) != 0)
    {
      printf ("Compact (1) failed!\n");
      exit (1);
    }
  stack = org;
}
Exemplo n.º 4
0
static void
test_nan_inf_zero (void)
{
  mpfr_ptr val;
  int sign;
  int kind;
  char *org = stack;

  val = new_mpfr (MPFR_PREC_MIN);

  mpfr_set_nan (val);
  kind = (mpfr_custom_get_kind) (val);
  if (kind != MPFR_NAN_KIND)
    {
      printf ("mpfr_custom_get_kind error : ");
      mpfr_dump (val);
      printf (" is kind %d instead of %d\n", kind, MPFR_NAN_KIND);
      exit (1);
    }

  sign = 1;
  mpfr_set_inf (val, sign);
  kind = (mpfr_custom_get_kind) (val);
  if ((ABS (kind) != MPFR_INF_KIND) || (SIGN (kind) != SIGN (sign)))
    {
      printf ("mpfr_custom_get_kind error : ");
      mpfr_dump (val);
      printf (" is kind %d instead of %d\n", kind, MPFR_INF_KIND);
      printf (" have sign %d instead of %d\n", SIGN (kind), SIGN (sign));
      exit (1);
    }

  sign = -1;
  mpfr_set_zero (val, sign);
  kind = (mpfr_custom_get_kind) (val);
  if ((ABS (kind) != MPFR_ZERO_KIND) || (SIGN (kind) != SIGN (sign)))
    {
      printf ("mpfr_custom_get_kind error : ");
      mpfr_dump (val);
      printf (" is kind %d instead of %d\n", kind, MPFR_ZERO_KIND);
      printf (" have sign %d instead of %d\n", SIGN (kind), SIGN (sign));
      exit (1);
    }

  stack = org;
}