Exemplo n.º 1
0
static void
check_special (void)
{
  __float128 f;
  mpfr_t x;

  mpfr_init2 (x, 113);

  /* check NaN */
  f = 0.0 / 0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (mpfr_nan_p (x) == 0)
    {
      printf ("Error in mpfr_set_float128(x, NaN)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f == f)
    {
      printf ("Error in mpfr_get_float128(NaN)\n");
      exit (1);
    }

  /* check +Inf */
  f = 1.0 / 0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (mpfr_inf_p (x) == 0 || mpfr_sgn (x) < 0)
    {
      printf ("Error in mpfr_set_float128(x, +Inf)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f != (1.0 / 0.0))
    {
      printf ("Error in mpfr_get_float128(+Inf)\n");
      exit (1);
    }

  /* check -Inf */
  f = -1.0 / 0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (mpfr_inf_p (x) == 0 || mpfr_sgn (x) > 0)
    {
      printf ("Error in mpfr_set_float128(x, -Inf)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f != (-1.0 / 0.0))
    {
      printf ("Error in mpfr_get_float128(-Inf)\n");
      exit (1);
    }

  /* check +0 */
  f = 0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (mpfr_zero_p (x) == 0 || mpfr_sgn (x) < 0)
    {
      printf ("Error in mpfr_set_float128(x, +0)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f != 0.0 || 1 / f != 1 / 0.0)
    {
      printf ("Error in mpfr_get_float128(+0.0)\n");
      exit (1);
    }

  /* check -0 */
  f = -0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (mpfr_zero_p (x) == 0 || mpfr_sgn (x) > 0)
    {
      printf ("Error in mpfr_set_float128(x, -0)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f != -0.0 || 1 / f != 1 / -0.0)
    {
      printf ("Error in mpfr_get_float128(-0.0)\n");
      exit (1);
    }

  mpfr_clear (x);
}
Exemplo n.º 2
0
static void
check_large (void)
{
  __float128 f, e;
  int i;
  mpfr_t x, y;
  mpfr_rnd_t r;

  mpfr_init2 (x, 113);
  mpfr_init2 (y, 113);

  /* check with the largest float128 number 2^16384*(1-2^(-113)) */
  for (f = 1.0, i = 0; i < 113; i++)
    f = f + f;
  f = f - (__float128) 1.0;
  mpfr_set_ui (y, 1, MPFR_RNDN);
  mpfr_mul_2exp (y, y, 113, MPFR_RNDN);
  mpfr_sub_ui (y, y, 1, MPFR_RNDN);
  for (i = 113; i < 16384; i++)
    {
      for (r = 0; r < MPFR_RND_MAX; r++)
        {
          mpfr_set_float128 (x, f, r);
          if (! mpfr_equal_p (x, y))
            {
              printf ("mpfr_set_float128 failed for 2^%d*(1-2^(-113)) rnd=%s\n",
                      i, mpfr_print_rnd_mode (r));
              printf ("got ");
              mpfr_dump (x);
              exit (1);
            }
          e =  mpfr_get_float128 (x, r);
          if (e != f)
            {
              printf ("mpfr_get_float128 failed for 2^%d*(1-2^(-113)) rnd=%s\n",
                      i, mpfr_print_rnd_mode (r));
              exit (1);
            }
        }

      /* check with opposite number */
      f = -f;
      mpfr_neg (y, y, MPFR_RNDN);
      for (r = 0; r < MPFR_RND_MAX; r++)
        {
          mpfr_set_float128 (x, f, r);
          if (! mpfr_equal_p (x, y))
            {
              printf ("mpfr_set_float128 failed for -2^%d*(1-2^(-113)) rnd=%s\n",
                      i, mpfr_print_rnd_mode (r));
              printf ("got ");
              mpfr_dump (x);
              exit (1);
            }
          e =  mpfr_get_float128 (x, r);
          if (e != f)
            {
              printf ("mpfr_get_float128 failed for -2^%d*(1-2^(-113)) rnd=%s\n",
                      i, mpfr_print_rnd_mode (r));
              exit (1);
            }
        }

      f = -f;
      mpfr_neg (y, y, MPFR_RNDN);
      f = f + f;
      mpfr_add (y, y, y, MPFR_RNDN);
    }

  mpfr_clear (x);
  mpfr_clear (y);
}
Exemplo n.º 3
0
static void
check_small (void)
{
  __float128 f, e;
  int i;
  mpfr_t x, y;
  mpfr_rnd_t r;

  mpfr_init2 (x, 113);
  mpfr_init2 (y, 113);

  /* check with the smallest positive normal float128 number */
  f = 1.0;
  mpfr_set_ui (y, 1, MPFR_RNDN);
  for (i = 0; f != 0.0; i--)
    {
      for (r = 0; r < MPFR_RND_MAX; r++)
        {
          mpfr_set_float128 (x, f, r);
          if (! mpfr_equal_p (x, y))
            {
              printf ("mpfr_set_float128 failed for 2^%d rnd=%s\n", i,
                      mpfr_print_rnd_mode (r));
              printf ("got ");
              mpfr_dump (x);
              exit (1);
            }
          e =  mpfr_get_float128 (x, r);
          if (e != f)
            {
              printf ("mpfr_get_float128 failed for 2^%d rnd=%s\n",
                      i, mpfr_print_rnd_mode (r));
              exit (1);
            }

          /* check with opposite number */
          mpfr_set_float128 (x, -f, r);
          mpfr_neg  (y, y, MPFR_RNDN);
          if (! mpfr_equal_p (x, y))
            {
              printf ("mpfr_set_float128 failed for -2^%d rnd=%s\n", i,
                      mpfr_print_rnd_mode (r));
              printf ("got ");
              mpfr_dump (x);
              exit (1);
            }
          if (e != f)
            {
              printf ("mpfr_get_float128 failed for -2^%d rnd=%s\n",
                      i, mpfr_print_rnd_mode (r));
              exit (1);
            }

          mpfr_neg  (y, y, MPFR_RNDN);
        }
      f =  0.5 * f;
      mpfr_div_2exp (y, y, 1, MPFR_RNDN);
    }

  mpfr_clear (x);
  mpfr_clear (y);
}
Exemplo n.º 4
0
static void
check_special (void)
{
  __float128 f;
  mpfr_t x;

  mpfr_init2 (x, 113);

#if !defined(MPFR_ERRDIVZERO)
  /* check NaN */
  f = 0.0 / 0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (! mpfr_nan_p (x))
    {
      printf ("Error in mpfr_set_float128(x, NaN)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (! DOUBLE_ISNAN (f))
    {
      printf ("Error in mpfr_get_float128(NaN)\n");
      printf ("got %f\n", (double) f);
      exit (1);
    }

  /* check +Inf */
  f = 1.0 / 0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (! mpfr_inf_p (x) || MPFR_IS_NEG (x))
    {
      printf ("Error in mpfr_set_float128(x, +Inf)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f != (1.0 / 0.0))
    {
      printf ("Error in mpfr_get_float128(+Inf)\n");
      exit (1);
    }

  /* check -Inf */
  f = -1.0 / 0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (! mpfr_inf_p (x) || MPFR_IS_POS (x))
    {
      printf ("Error in mpfr_set_float128(x, -Inf)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f != (-1.0 / 0.0))
    {
      printf ("Error in mpfr_get_float128(-Inf)\n");
      exit (1);
    }
#endif

  /* check +0 */
  f = 0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (! mpfr_zero_p (x) || MPFR_IS_NEG (x))
    {
      printf ("Error in mpfr_set_float128(x, +0)\n");
      exit (1);
    }
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f != 0.0)  /* the sign is not checked */
    {
      printf ("Error in mpfr_get_float128(+0.0)\n");
      exit (1);
    }
#if !defined(MPFR_ERRDIVZERO) && defined(HAVE_SIGNEDZ)
  if (1 / f != 1 / 0.0)  /* check the sign */
    {
      printf ("Error in mpfr_get_float128(+0.0)\n");
      exit (1);
    }
#endif

  /* check -0 */
  f = -0.0;
  mpfr_set_float128 (x, f, MPFR_RNDN);
  if (! mpfr_zero_p (x))
    {
      printf ("Error in mpfr_set_float128(x, -0)\n");
      exit (1);
    }
#if defined(HAVE_SIGNEDZ)
  if (MPFR_IS_POS (x))
    {
      printf ("Error in mpfr_set_float128(x, -0)\n");
      exit (1);
    }
#endif
  f = mpfr_get_float128 (x, MPFR_RNDN);
  if (f != -0.0)  /* the sign is not checked */
    {
      printf ("Error in mpfr_get_float128(-0.0)\n");
      exit (1);
    }
#if !defined(MPFR_ERRDIVZERO) && defined(HAVE_SIGNEDZ)
  if (1 / f != 1 / -0.0)  /* check the sign */
    {
      printf ("Error in mpfr_get_float128(-0.0)\n");
      exit (1);
    }
#endif

  mpfr_clear (x);
}