当前位置: 首页>>代码示例>>C++>>正文


C++ set_emax函数代码示例

本文整理汇总了C++中set_emax函数的典型用法代码示例。如果您正苦于以下问题:C++ set_emax函数的具体用法?C++ set_emax怎么用?C++ set_emax使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了set_emax函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: special_overflow

static void
special_overflow (void)
{
  mpfr_t x, y;
  mpfr_exp_t emin, emax;

  emin = mpfr_get_emin ();
  emax = mpfr_get_emax ();

  set_emin (-125);
  set_emax (128);
  mpfr_init2 (x, 24);
  mpfr_init2 (y, 48);
  mpfr_set_str_binary (x, "0.101100100000000000110100E0");
  mpfr_asin (y, x, MPFR_RNDN);
  if (mpfr_cmp_str (y, "0.110001001101001111110000010110001000111011001000E0",
                    2, MPFR_RNDN))
    {
      printf("Special Overflow error.\n");
      mpfr_dump (y);
      exit (1);
    }
  mpfr_clear (y);
  mpfr_clear (x);
  set_emin (emin);
  set_emax (emax);
}
开发者ID:Canar,项目名称:mpfr,代码行数:27,代码来源:tasin.c

示例2: check_overflow

static void
check_overflow (void)
{
  mpfr_t x, y, z1, z2;
  mpfr_exp_t emin, emax;

  emin = mpfr_get_emin ();
  emax = mpfr_get_emax ();

  set_emin (-1021);
  set_emax (1024);

  mpfr_inits (x, y, z1, z2, (mpfr_ptr) 0);

  mpfr_set_str1 (x, "8.00468257869324898448e+307");
  mpfr_set_str1 (y, "7.44784712422708645156e+307");
  mpfr_add1sp (z1, x, y, MPFR_RNDN);
  mpfr_add1   (z2, x, y, MPFR_RNDN);
  if (mpfr_cmp (z1, z2))
    {
      printf ("Overflow bug in add1sp.\n");
      exit (1);
    }
  mpfr_clears (x, y, z1, z2, (mpfr_ptr) 0);

  set_emin (emin);
  set_emax (emax);
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.toolchain,代码行数:28,代码来源:tadd1sp.c

示例3: special_overflow

static void
special_overflow (void)
{
  mpfr_t x, y;
  int inex;
  mpfr_exp_t emin, emax;

  emin = mpfr_get_emin ();
  emax = mpfr_get_emax ();

  set_emin (-125);
  set_emax (128);

  mpfr_init2 (x, 24);
  mpfr_init2 (y, 24);

  mpfr_set_str_binary (x, "0.101100100000000000110100E15");
  inex = mpfr_exp2 (y, x, MPFR_RNDN);
  if (!mpfr_inf_p (y) || inex <= 0)
    {
      printf ("Overflow error.\n");
      mpfr_dump (y);
      printf ("inex = %d\n", inex);
      exit (1);
    }

  mpfr_clear (y);
  mpfr_clear (x);
  set_emin (emin);
  set_emax (emax);
}
开发者ID:sudheesh001,项目名称:SEC-LAB,代码行数:31,代码来源:texp2.c

示例4: check_emax_aux

/* In particular, the following test makes sure that the rounding
 * for %Ra and %Rb is not done on the MPFR number itself (as it
 * would overflow). Note: it has been reported on comp.std.c that
 * some C libraries behave differently on %a, but this is a bug.
 */
static void
check_emax_aux (mpfr_exp_t e)
{
    mpfr_t x;
    char *s1, s2[256];
    int i;
    mpfr_exp_t emax;

    MPFR_ASSERTN (e <= LONG_MAX);
    emax = mpfr_get_emax ();
    set_emax (e);

    mpfr_init2 (x, 16);

    mpfr_set_inf (x, 1);
    mpfr_nextbelow (x);

    i = mpfr_asprintf (&s1, "%Ra %.2Ra", x, x);
    MPFR_ASSERTN (i > 0);

    mpfr_snprintf (s2, 256, "0x7.fff8p+%ld 0x8.00p+%ld", e-3, e-3);

    if (strcmp (s1, s2) != 0)
    {
        printf ("Error in check_emax_aux for emax = ");
        if (e > LONG_MAX)
            printf ("(>LONG_MAX)\n");
        else
            printf ("%ld\n", (long) e);
        printf ("Expected %s\n", s2);
        printf ("Got      %s\n", s1);
        exit (1);
    }

    mpfr_free_str (s1);

    i = mpfr_asprintf (&s1, "%Rb %.2Rb", x, x);
    MPFR_ASSERTN (i > 0);

    mpfr_snprintf (s2, 256, "1.111111111111111p+%ld 1.00p+%ld", e-1, e);

    if (strcmp (s1, s2) != 0)
    {
        printf ("Error in check_emax_aux for emax = ");
        if (e > LONG_MAX)
            printf ("(>LONG_MAX)\n");
        else
            printf ("%ld\n", (long) e);
        printf ("Expected %s\n", s2);
        printf ("Got      %s\n", s1);
        exit (1);
    }

    mpfr_free_str (s1);

    mpfr_clear (x);
    set_emax (emax);
}
开发者ID:epowers,项目名称:mpfr,代码行数:63,代码来源:tsprintf.c

示例5: main

int
main (void)
{
  mpfr_t x, y, z, u;
  int inexact;
  mpfr_exp_t emax;

  tests_start_mpfr ();

  /* check prototypes of mpfr_init_set_* */
  inexact = mpfr_init_set_si (x, -1, MPFR_RNDN);
  inexact = mpfr_init_set (y, x, MPFR_RNDN);
  inexact = mpfr_init_set_ui (z, 1, MPFR_RNDN);
  inexact = mpfr_init_set_d (u, 1.0, MPFR_RNDN);

  emax = mpfr_get_emax ();
  set_emax (0);
  mpfr_set_prec (x, 3);
  mpfr_set_str_binary (x, "0.111");
  mpfr_set_prec (y, 2);
  mpfr_set (y, x, MPFR_RNDU);
  if (!(MPFR_IS_INF (y) && MPFR_SIGN (y) > 0))
    {
      printf ("Error for y=x=0.111 with px=3, py=2 and emax=0\nx=");
      mpfr_dump (x);
      printf ("y=");
      mpfr_dump (y);
      exit (1);
    }

  set_emax (emax);

  mpfr_set_prec (y, 11);
  mpfr_set_str_binary (y, "0.11111111100E-8");
  mpfr_set_prec (x, 2);
  mpfr_set (x, y, MPFR_RNDN);
  mpfr_set_str_binary (y, "1.0E-8");
  if (mpfr_cmp (x, y))
    {
      printf ("Error for y=0.11111111100E-8, prec=2, rnd=MPFR_RNDN\n");
      exit (1);
    }

  mpfr_clear (x);
  mpfr_clear (y);
  mpfr_clear (z);
  mpfr_clear (u);

  check_ternary_value ();
  check_special ();
  check_neg_special ();

  test_generic (2, 1000, 10);

  tests_end_mpfr ();
  return 0;
}
开发者ID:119,项目名称:aircam-openwrt,代码行数:57,代码来源:tset.c

示例6: special_overflow

static void
special_overflow (void)
{
  /* Check for overflow in 3 cases:
     1. cosh(x) is representable, but not exp(x)
     2. cosh(x) is not representable in the selected range of exp.
     3. cosh(x) exp overflow even with the largest range of exp */
  mpfr_t x, y;
  mp_exp_t emin, emax;

  emin = mpfr_get_emin ();
  emax = mpfr_get_emax ();

  set_emin (-125);
  set_emax (128);

  mpfr_init2 (x, 24);
  mpfr_init2 (y, 24);

  mpfr_set_str_binary (x, "0.101100100000000000110100E7");
  mpfr_cosh (y, x, GMP_RNDN);
  if (mpfr_cmp_str (y, "0.101010001111001010001110E128", 2, GMP_RNDN))
    {
      printf("Special overflow error 1.\n");
      mpfr_dump (y);
      exit (1);
    }

  mpfr_set_str_binary (x, "0.101100100000000000110100E8");
  mpfr_cosh (y, x, GMP_RNDN);
  if (!mpfr_inf_p(y))
    {
      printf("Special overflow error 2.\n");
      mpfr_dump (y);
      exit (1);
    }

  set_emin (emin);
  set_emax (emax);

  mpfr_set_str_binary (x, "0.101100100000000000110100E1000000");
  mpfr_cosh (y, x, GMP_RNDN);
  if (!mpfr_inf_p(y))
    {
      printf("Special overflow error 3.\n");
      mpfr_dump (y);
      exit (1);
    }

  mpfr_clear (y);
  mpfr_clear (x);
}
开发者ID:STAR111,项目名称:GCC_parser,代码行数:52,代码来源:tcosh.c

示例7: check_overflow

static void
check_overflow (void)
{
  mpfr_t sum1, sum2, x, y;
  mpfr_ptr t[2 * NOVFL];
  mpfr_exp_t emin, emax;
  int i, r;

  emin = mpfr_get_emin ();
  emax = mpfr_get_emax ();
  set_emin (MPFR_EMIN_MIN);
  set_emax (MPFR_EMAX_MAX);

  mpfr_inits2 (32, sum1, sum2, x, y, (mpfr_ptr) 0);
  mpfr_setmax (x, mpfr_get_emax ());
  mpfr_neg (y, x, MPFR_RNDN);

  for (i = 0; i < 2 * NOVFL; i++)
    t[i] = i < NOVFL ? x : y;

  /* Two kinds of test:
   *   i = 1: overflow.
   *   i = 2: intermediate overflow (exact sum is 0).
   */
  for (i = 1; i <= 2; i++)
    RND_LOOP(r)
      {
        int inex1, inex2;

        inex1 = mpfr_add (sum1, x, i == 1 ? x : y, (mpfr_rnd_t) r);
        inex2 = mpfr_sum (sum2, t, i * NOVFL, (mpfr_rnd_t) r);
        MPFR_ASSERTN (mpfr_check (sum1));
        MPFR_ASSERTN (mpfr_check (sum2));
        if (!(mpfr_equal_p (sum1, sum2) && SAME_SIGN (inex1, inex2)))
          {
            printf ("Error in check_overflow on %s, i = %d\n",
                    mpfr_print_rnd_mode ((mpfr_rnd_t) r), i);
            printf ("Expected ");
            mpfr_dump (sum1);
            printf ("with inex = %d\n", inex1);
            printf ("Got      ");
            mpfr_dump (sum2);
            printf ("with inex = %d\n", inex2);
            exit (1);
          }
      }

  mpfr_clears (sum1, sum2, x, y, (mpfr_ptr) 0);

  set_emin (emin);
  set_emax (emax);
}
开发者ID:BrianGladman,项目名称:mpfr,代码行数:52,代码来源:tsum.c

示例8: check_large

static void
check_large (void)
{
  mpz_t z;
  mpfr_t x, y;
  mpfr_exp_t emax, emin;

  mpz_init (z);
  mpfr_init2 (x, 160);
  mpfr_init2 (y, 160);

  mpz_set_str (z, "77031627725494291259359895954016675357279104942148788042", 10);
  mpfr_set_z (x, z, MPFR_RNDN);
  mpfr_set_str_binary (y, "0.1100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001001E186");
  if (mpfr_cmp (x, y))
    {
      printf ("Error in mpfr_set_z on large input\n");
      exit (1);
    }

  /* check overflow */
  emax = mpfr_get_emax ();
  set_emax (2);
  mpz_set_str (z, "7", 10);
  mpfr_set_z (x, z, MPFR_RNDU);
  MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
  set_emax (3);
  mpfr_set_prec (x, 2);
  mpz_set_str (z, "7", 10);
  mpfr_set_z (x, z, MPFR_RNDU);
  MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
  set_emax (emax);

  /* check underflow */
  emin = mpfr_get_emin ();
  set_emin (3);
  mpz_set_str (z, "1", 10);
  mpfr_set_z (x, z, MPFR_RNDZ);
  MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
  set_emin (2);
  mpfr_set_z (x, z, MPFR_RNDN);
  MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x));
  set_emin (emin);

  mpz_clear (z);

  mpfr_clear (x);
  mpfr_clear (y);
}
开发者ID:BreakawayConsulting,项目名称:mpfr,代码行数:49,代码来源:tset_z.c

示例9: check_emin_emax

static void
check_emin_emax (void)
{
    mpfr_exp_t old_emin, old_emax;

    old_emin = mpfr_get_emin ();
    old_emax = mpfr_get_emax ();

    /* Check the functions not the macros ! */
    if ((mpfr_set_emin)(MPFR_EMIN_MIN) != 0)
        ERROR("set_emin failed!");
    if ((mpfr_get_emin)() != MPFR_EMIN_MIN)
        ERROR("get_emin FAILED!");
    if ((mpfr_set_emin)(MPFR_EMIN_MIN-1) == 0)
        ERROR("set_emin failed! (2)");

    if ((mpfr_set_emax)(MPFR_EMAX_MAX) != 0)
        ERROR("set_emax failed!");
    if ((mpfr_get_emax)() != MPFR_EMAX_MAX)
        ERROR("get_emax FAILED!");
    if ((mpfr_set_emax)(MPFR_EMAX_MAX+1) == 0)
        ERROR("set_emax failed! (2)");

    if ((mpfr_get_emin_min) () != MPFR_EMIN_MIN)
        ERROR ("get_emin_min");
    if ((mpfr_get_emin_max) () != MPFR_EMIN_MAX)
        ERROR ("get_emin_max");
    if ((mpfr_get_emax_min) () != MPFR_EMAX_MIN)
        ERROR ("get_emax_min");
    if ((mpfr_get_emax_max) () != MPFR_EMAX_MAX)
        ERROR ("get_emax_max");

    set_emin (old_emin);
    set_emax (old_emax);
}
开发者ID:gnooth,项目名称:xcl,代码行数:35,代码来源:texceptions.c

示例10: mpfr_set_double_range

static void
mpfr_set_double_range (void)
{
    mpfr_set_default_prec (54);
    if (mpfr_get_default_prec () != 54)
        ERROR ("get_default_prec failed (1)");
    mpfr_set_default_prec (53);
    if ((mpfr_get_default_prec) () != 53)
        ERROR ("get_default_prec failed (2)");

    /* in double precision format, the unbiased exponent is between 0 and
       2047, where 0 is used for subnormal numbers, and 2047 for special
       numbers (infinities, NaN), and the bias is 1023, thus "normal" numbers
       have an exponent between -1022 and 1023, corresponding to numbers
       between 2^(-1022) and previous(2^(1024)).
       (The smallest subnormal number is 0.(0^51)1*2^(-1022)= 2^(-1074).)

       The smallest normal power of two is 1.0*2^(-1022).
       The largest normal power of two is 2^1023.
       (We have to add one for mpfr since mantissa are between 1/2 and 1.)
    */

    set_emin (-1021);
    set_emax (1024);
}
开发者ID:gnooth,项目名称:xcl,代码行数:25,代码来源:texceptions.c

示例11: reduced_expo_range

/* https://sympa.inria.fr/sympa/arc/mpfr/2011-05/msg00008.html
 * Incorrect flags (in debug mode on a 32-bit machine, assertion failure).
 */
static void
reduced_expo_range (void)
{
    mpfr_exp_t emin, emax;
    mpfr_t x, y, ex_y;
    int inex, ex_inex;
    unsigned int flags, ex_flags;

    emin = mpfr_get_emin ();
    emax = mpfr_get_emax ();

    mpfr_inits2 (12, x, y, ex_y, (mpfr_ptr) 0);
    mpfr_set_str (x, "0.1e-5", 2, MPFR_RNDN);

    set_emin (-5);
    set_emax (-5);
    mpfr_clear_flags ();
    inex = mpfr_atan (y, x, MPFR_RNDN);
    flags = __gmpfr_flags;
    set_emin (emin);
    set_emax (emax);

    mpfr_set_str (ex_y, "0.1e-5", 2, MPFR_RNDN);
    ex_inex = 1;
    ex_flags = MPFR_FLAGS_INEXACT;

    if (SIGN (inex) != ex_inex || flags != ex_flags ||
            ! mpfr_equal_p (y, ex_y))
    {
        printf ("Error in reduced_expo_range\non x = ");
        mpfr_dump (x);
        printf ("Expected y = ");
        mpfr_out_str (stdout, 2, 0, ex_y, MPFR_RNDN);
        printf ("\n         inex = %d, flags = %u\n", ex_inex, ex_flags);
        printf ("Got      y = ");
        mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
        printf ("\n         inex = %d, flags = %u\n", SIGN (inex), flags);
        exit (1);
    }

    mpfr_clears (x, y, ex_y, (mpfr_ptr) 0);
}
开发者ID:Canar,项目名称:mpfr,代码行数:45,代码来源:tatan.c

示例12: main

int
main (int argc, char *argv[])
{
  mpfr_t x;
  int ret;
  mpfr_exp_t emin, emax;

  tests_start_mpfr ();

  emin = mpfr_get_emin ();
  emax = mpfr_get_emax ();

  mpfr_init (x);

  mpfr_set_ui (x, 1, MPFR_RNDN);
  ret = mpfr_set_exp (x, 2);
  MPFR_ASSERTN(ret == 0 && mpfr_cmp_ui (x, 2) == 0);

  set_emin (-1);
  ret = mpfr_set_exp (x, -1);
  MPFR_ASSERTN(ret == 0 && mpfr_cmp_ui_2exp (x, 1, -2) == 0);

  set_emax (1);
  ret = mpfr_set_exp (x, 1);
  MPFR_ASSERTN(ret == 0 && mpfr_cmp_ui (x, 1) == 0);

  ret = mpfr_set_exp (x, -2);
  MPFR_ASSERTN(ret != 0 && mpfr_cmp_ui (x, 1) == 0);

  ret = mpfr_set_exp (x, 2);
  MPFR_ASSERTN(ret != 0 && mpfr_cmp_ui (x, 1) == 0);

  mpfr_clear (x);

  set_emin (emin);
  set_emax (emax);

  tests_end_mpfr ();
  return 0;
}
开发者ID:SESA,项目名称:EbbRT-mpfr,代码行数:40,代码来源:tset_exp.c

示例13: check_reduced_exprange

static void
check_reduced_exprange (void)
{
  mpfr_t x;
  char *s;
  mpfr_exp_t emax, e;

  emax = mpfr_get_emax ();
  mpfr_init2 (x, 8);
  mpfr_set_str (x, "0.11111111E0", 2, MPFR_RNDN);
  set_emax (0);
  s = mpfr_get_str (NULL, &e, 16, 0, x, MPFR_RNDN);
  set_emax (emax);
  if (strcmp (s, "ff0"))
    {
      printf ("Error for mpfr_get_str on 0.11111111E0 in base 16:\n"
              "Got \"%s\" instead of \"ff0\".\n", s);
      exit (1);
    }
  mpfr_free_str (s);
  mpfr_clear (x);
}
开发者ID:BrianGladman,项目名称:mpfr,代码行数:22,代码来源:tget_str.c

示例14: special_overflow

static void
special_overflow (void)
{
  mpfr_t x, y;
  mpfr_exp_t emin, emax;

  emin = mpfr_get_emin ();
  emax = mpfr_get_emax ();

  mpfr_init2 (x, 24);
  mpfr_init2 (y, 73);

  /* Check special case: An overflow in const_pi could occurs! */
  set_emin (-125);
  set_emax (128);
  mpfr_set_str_binary (x, "0.111101010110110011101101E6");
  test_cos (y, x, MPFR_RNDZ);
  set_emin (emin);
  set_emax (emax);

  mpfr_clear (x);
  mpfr_clear (y);
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.toolchain,代码行数:23,代码来源:tcos.c

示例15: check_flags

static void
check_flags (void)
{
    mpfr_t x;
    mpfr_exp_t old_emin, old_emax;

    old_emin = mpfr_get_emin ();
    old_emax = mpfr_get_emax ();
    mpfr_init (x);

    /* Check the functions not the macros ! */
    (mpfr_clear_flags)();
    mpfr_set_double_range ();

    mpfr_set_ui (x, 1, MPFR_RNDN);
    (mpfr_clear_overflow)();
    mpfr_mul_2exp (x, x, 1024, MPFR_RNDN);
    if (!(mpfr_overflow_p)())
        ERROR("ERROR: No overflow detected!\n");

    (mpfr_clear_underflow)();
    mpfr_set_ui (x, 1, MPFR_RNDN);
    mpfr_div_2exp (x, x, 1025, MPFR_RNDN);
    if (!(mpfr_underflow_p)())
        ERROR("ERROR: No underflow detected!\n");

    (mpfr_clear_nanflag)();
    MPFR_SET_NAN(x);
    mpfr_add (x, x, x, MPFR_RNDN);
    if (!(mpfr_nanflag_p)())
        ERROR("ERROR: No NaN flag!\n");

    (mpfr_clear_inexflag)();
    mpfr_set_ui(x, 2, MPFR_RNDN);
    mpfr_cos(x, x, MPFR_RNDN);
    if (!(mpfr_inexflag_p)())
        ERROR("ERROR: No inexact flag!\n");

    (mpfr_clear_erangeflag) ();
    mpfr_set_ui (x, 1, MPFR_RNDN);
    mpfr_mul_2exp (x, x, 1024, MPFR_RNDN);
    mpfr_get_ui (x, MPFR_RNDN);
    if (!(mpfr_erangeflag_p)())
        ERROR ("ERROR: No erange flag!\n");

    mpfr_clear (x);
    set_emin (old_emin);
    set_emax (old_emax);
}
开发者ID:gnooth,项目名称:xcl,代码行数:49,代码来源:texceptions.c


注:本文中的set_emax函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。