Example #1
0
/* tsin_cos prec [N] performs N tests with prec bits */
int
main (int argc, char *argv[])
{
  tests_start_mpfr ();

  if (argc > 1)
    {
      if (argc != 3 && argc != 4)
        {
          fprintf (stderr, "Usage: tsin_cos x prec [n]\n");
          exit (1);
        }
      large_test (argv[1], atoi (argv[2]), (argc > 3) ? atoi (argv[3]) : 1);
      goto end;
    }

  bug20091013 ();
  bug20091008 ();
  bug20091007 ();
  bug20091122 ();
  consistency ();

  test_mpfr_sincos_fast ();

  check_nans ();

  /* worst case from PhD thesis of Vincent Lefe`vre: x=8980155785351021/2^54 */
  check53 ("4.984987858808754279e-1", "4.781075595393330379e-1",
           "8.783012931285841817e-1", MPFR_RNDN);
  check53 ("4.984987858808754279e-1", "4.781075595393329824e-1",
           "8.783012931285840707e-1", MPFR_RNDD);
  check53 ("4.984987858808754279e-1", "4.781075595393329824e-1",
           "8.783012931285840707e-1", MPFR_RNDZ);
  check53 ("4.984987858808754279e-1", "4.781075595393330379e-1",
           "8.783012931285841817e-1", MPFR_RNDU);
  check53 ("1.00031274099908640274",  "8.416399183372403892e-1",
           "0.540039116973283217504", MPFR_RNDN);
  check53 ("1.00229256850978698523",  "8.427074524447979442e-1",
           "0.538371757797526551137", MPFR_RNDZ);
  check53 ("1.00288304857059840103",  "8.430252033025980029e-1",
           "0.537874062022526966409", MPFR_RNDZ);
  check53 ("1.00591265847407274059",  "8.446508805292128885e-1",
           "0.53531755997839769456",  MPFR_RNDN);

  /* check one argument only */
  check53sin ("1.00591265847407274059", "8.446508805292128885e-1", MPFR_RNDN);
  check53cos ("1.00591265847407274059", "0.53531755997839769456",  MPFR_RNDN);

  overflowed_sin_cos0 ();
  tiny ();
  test20071214 ();

  coverage_01032011 ();

 end:
  tests_end_mpfr ();
  return 0;
}
Example #2
0
int
main (int argc, char *argv[])
{
  tests_start_mpfr ();

  check_nans ();
  check_exact ();
  check_float ();

  check53("6.9314718055994530941514e-1", "0.0", MPFR_RNDZ, "0.0");
  check53("0.0", "6.9314718055994530941514e-1", MPFR_RNDZ, "0.0");
  check_sign();
  check53("-4.165000000e4", "-0.00004801920768307322868063274915", MPFR_RNDN,
          "2.0");
  check53("2.71331408349172961467e-08", "-6.72658901114033715233e-165",
          MPFR_RNDZ, "-1.8251348697787782844e-172");
  check53("2.71331408349172961467e-08", "-6.72658901114033715233e-165",
          MPFR_RNDA, "-1.8251348697787786e-172");
  check53("0.31869277231188065", "0.88642843322303122", MPFR_RNDZ,
          "2.8249833483992453642e-1");
  check("8.47622108205396074254e-01", "3.24039313247872939883e-01", MPFR_RNDU,
        28, 45, 2, "0.375");
  check("8.47622108205396074254e-01", "3.24039313247872939883e-01", MPFR_RNDA,
        28, 45, 2, "0.375");
  check("2.63978122803639081440e-01", "6.8378615379333496093e-1", MPFR_RNDN,
        34, 23, 31, "0.180504585267044603");
  check("1.0", "0.11835170935876249132", MPFR_RNDU, 6, 41, 36,
        "0.1183517093595583");
  check53("67108865.0", "134217729.0", MPFR_RNDN, "9.007199456067584e15");
  check("1.37399642157394197284e-01", "2.28877275604219221350e-01", MPFR_RNDN,
        49, 15, 32, "0.0314472340833162888");
  check("4.03160720978664954828e-01", "5.854828e-1"
        /*"5.85483042917246621073e-01"*/, MPFR_RNDZ,
        51, 22, 32, "0.2360436821472831");
  check("3.90798504668055102229e-14", "9.85394674650308388664e-04", MPFR_RNDN,
        46, 22, 12, "0.385027296503914762e-16");
  check("4.58687081072827851358e-01", "2.20543551472118792844e-01", MPFR_RNDN,
        49, 3, 2, "0.09375");
  check_max();
  check_min();

  check_regression ();
  test_generic (2, 500, 100);

  data_check ("data/mulpi", mpfr_mulpi, "mpfr_mulpi");

  valgrind20110503 ();

  tests_end_mpfr ();
  return 0;
}
int
main (int argc, char *argv[])
{
  mpfr_t x, y;
  int inex;

  tests_start_mpfr ();

  special_overflow ();
  check_nans ();

  mpfr_init (x);
  mpfr_init (y);

  mpfr_set_prec (x, 53);
  mpfr_set_prec (y, 2);
  mpfr_set_str (x, "9.81333845856942e-1", 10, MPFR_RNDN);
  test_cos (y, x, MPFR_RNDN);

  mpfr_set_prec (x, 30);
  mpfr_set_prec (y, 30);
  mpfr_set_str_binary (x, "1.00001010001101110010100010101e-1");
  test_cos (y, x, MPFR_RNDU);
  mpfr_set_str_binary (x, "1.10111100010101011110101010100e-1");
  if (mpfr_cmp (y, x))
    {
      printf ("Error for prec=30, rnd=MPFR_RNDU\n");
      printf ("expected "); mpfr_print_binary (x); puts ("");
      printf ("     got "); mpfr_print_binary (y); puts ("");
      exit (1);
    }

  mpfr_set_prec (x, 59);
  mpfr_set_prec (y, 59);
  mpfr_set_str_binary (x, "1.01101011101111010011111110111111111011011101100111100011e-3");
  test_cos (y, x, MPFR_RNDU);
  mpfr_set_str_binary (x, "1.1111011111110010001001001011100111101110100010000010010011e-1");
  if (mpfr_cmp (y, x))
    {
      printf ("Error for prec=59, rnd=MPFR_RNDU\n");
      printf ("expected "); mpfr_print_binary (x); puts ("");
      printf ("     got "); mpfr_print_binary (y); puts ("");
      exit (1);
    }

  mpfr_set_prec (x, 5);
  mpfr_set_prec (y, 5);
  mpfr_set_str_binary (x, "1.1100e-2");
  test_cos (y, x, MPFR_RNDD);
  mpfr_set_str_binary (x, "1.1100e-1");
  if (mpfr_cmp (y, x))
    {
      printf ("Error for x=1.1100e-2, rnd=MPFR_RNDD\n");
      printf ("expected 1.1100e-1, got "); mpfr_print_binary (y); puts ("");
      exit (1);
    }

  mpfr_set_prec (x, 32);
  mpfr_set_prec (y, 32);

  mpfr_set_str_binary (x, "0.10001000001001011000100001E-6");
  mpfr_set_str_binary (y, "0.1111111111111101101111001100001");
  test_cos (x, x, MPFR_RNDN);
  if (mpfr_cmp (x, y))
    {
      printf ("Error for prec=32 (1)\n");
      exit (1);
    }

  mpfr_set_str_binary (x, "-0.1101011110111100111010011001011E-1");
  mpfr_set_str_binary (y, "0.11101001100110111011011010100011");
  test_cos (x, x, MPFR_RNDN);
  if (mpfr_cmp (x, y))
    {
      printf ("Error for prec=32 (2)\n");
      exit (1);
    }

  /* huge argument reduction */
  mpfr_set_str_binary (x, "0.10000010000001101011101111001011E40");
  mpfr_set_str_binary (y, "0.10011000001111010000101011001011E-1");
  test_cos (x, x, MPFR_RNDN);
  if (mpfr_cmp (x, y))
    {
      printf ("Error for prec=32 (3)\n");
      exit (1);
    }

  mpfr_set_prec (x, 3);
  mpfr_set_prec (y, 3);
  mpfr_set_str_binary (x, "0.110E60");
  inex = mpfr_cos (y, x, MPFR_RNDD);
  MPFR_ASSERTN(inex < 0);

  /* worst case from PhD thesis of Vincent Lefe`vre: x=8980155785351021/2^54 */
  check53 ("4.984987858808754279e-1", "8.783012931285841817e-1", MPFR_RNDN);
  check53 ("4.984987858808754279e-1", "8.783012931285840707e-1", MPFR_RNDD);
  check53 ("4.984987858808754279e-1", "8.783012931285840707e-1", MPFR_RNDZ);
  check53 ("4.984987858808754279e-1", "8.783012931285841817e-1", MPFR_RNDU);
  check53 ("1.00031274099908640274",  "0.540039116973283217504", MPFR_RNDN);
  check53 ("1.00229256850978698523",  "0.538371757797526551137", MPFR_RNDZ);
  check53 ("1.00288304857059840103",  "0.537874062022526966409", MPFR_RNDZ);
  check53 ("1.00591265847407274059",  "0.53531755997839769456",  MPFR_RNDN);

  check53 ("1.00591265847407274059", "0.53531755997839769456",  MPFR_RNDN);

  overflowed_cos0 ();
  test_generic (2, 100, 15);

  /* check inexact flag */
  mpfr_set_prec (x, 3);
  mpfr_set_prec (y, 13);
  mpfr_set_str_binary (x, "-0.100E196");
  inex = mpfr_cos (y, x, MPFR_RNDU);
  mpfr_set_prec (x, 13);
  mpfr_set_str_binary (x, "0.1111111100101");
  MPFR_ASSERTN (inex > 0 && mpfr_equal_p (x, y));

  mpfr_clear (x);
  mpfr_clear (y);

  bug20091030 ();

  data_check ("data/cos", mpfr_cos, "mpfr_cos");
  bad_cases (mpfr_cos, mpfr_acos, "mpfr_cos", 256, -40, 0, 4, 128, 800, 50);

  tests_end_mpfr ();
  return 0;
}
Example #4
0
static void
check_double(void)
{
  check53("0.0", "1.0", MPFR_RNDZ, "0.0");
  check53("-7.4988969224688591e63", "4.8816866450288732e306", MPFR_RNDD,
          "-1.5361282826510687291e-243");
  check53("-1.33225773037748601769e+199", "3.63449540676937123913e+79",
          MPFR_RNDZ, "-3.6655920045905428978e119");
  check53("9.89438396044940256501e-134", "5.93472984109987421717e-67",MPFR_RNDU,
          "1.6672003992376663654e-67");
  check53("9.89438396044940256501e-134", "5.93472984109987421717e-67",MPFR_RNDA,
          "1.6672003992376663654e-67");
  check53("9.89438396044940256501e-134", "-5.93472984109987421717e-67",
          MPFR_RNDU, "-1.6672003992376663654e-67");
  check53("-4.53063926135729747564e-308", "7.02293374921793516813e-84",
          MPFR_RNDD, "-6.4512060388748850857e-225");
  check53("6.25089225176473806123e-01","-2.35527154824420243364e-230",
          MPFR_RNDD, "-2.6540006635008291192e229");
  check53("6.25089225176473806123e-01","-2.35527154824420243364e-230",
          MPFR_RNDA, "-2.6540006635008291192e229");
  check53("6.52308934689126e15", "-1.62063546601505417497e273", MPFR_RNDN,
          "-4.0250194961676020848e-258");
  check53("1.04636807108079349236e-189", "3.72295730823253012954e-292",
          MPFR_RNDZ, "2.810583051186143125e102");
  /* problems found by Kevin under HP-PA */
  check53 ("2.861044553323177e-136", "-1.1120354257068143e+45", MPFR_RNDZ,
           "-2.5727998292003016e-181");
  check53 ("-4.0559157245809205e-127", "-1.1237723844524865e+77", MPFR_RNDN,
           "3.6091968273068081e-204");
  check53 ("-1.8177943561493235e-93", "-8.51233984260364e-104", MPFR_RNDU,
           "2.1354814184595821e+10");
}
Example #5
0
int
main (int argc, char *argv[])
{
  mpfr_t x, c, s, c2, s2;

  tests_start_mpfr ();

  check_regression ();
  check_nans ();

  /* worst case from PhD thesis of Vincent Lefe`vre: x=8980155785351021/2^54 */
  check53 ("4.984987858808754279e-1", "4.781075595393330379e-1", MPFR_RNDN);
  check53 ("4.984987858808754279e-1", "4.781075595393329824e-1", MPFR_RNDD);
  check53 ("4.984987858808754279e-1", "4.781075595393329824e-1", MPFR_RNDZ);
  check53 ("4.984987858808754279e-1", "4.781075595393330379e-1", MPFR_RNDU);
  check53 ("1.00031274099908640274",  "8.416399183372403892e-1", MPFR_RNDN);
  check53 ("1.00229256850978698523",  "8.427074524447979442e-1", MPFR_RNDZ);
  check53 ("1.00288304857059840103",  "8.430252033025980029e-1", MPFR_RNDZ);
  check53 ("1.00591265847407274059",  "8.446508805292128885e-1", MPFR_RNDN);

  /* Other worst cases showing a bug introduced on 2005-01-29 in rev 3248 */
  check53b ("1.0111001111010111010111111000010011010001110001111011e-21",
            "1.0111001111010111010111111000010011010001101001110001e-21",
            MPFR_RNDU);
  check53b ("1.1011101111111010000001010111000010000111100100101101",
            "1.1111100100101100001111100000110011110011010001010101e-1",
            MPFR_RNDU);

  mpfr_init2 (x, 2);

  mpfr_set_str (x, "0.5", 10, MPFR_RNDN);
  test_sin (x, x, MPFR_RNDD);
  if (mpfr_cmp_ui_2exp (x, 3, -3)) /* x != 0.375 = 3/8 */
    {
      printf ("mpfr_sin(0.5, MPFR_RNDD) failed with precision=2\n");
      exit (1);
    }

  /* bug found by Kevin Ryde */
  mpfr_const_pi (x, MPFR_RNDN);
  mpfr_mul_ui (x, x, 3L, MPFR_RNDN);
  mpfr_div_ui (x, x, 2L, MPFR_RNDN);
  test_sin (x, x, MPFR_RNDN);
  if (mpfr_cmp_ui (x, 0) >= 0)
    {
      printf ("Error: wrong sign for sin(3*Pi/2)\n");
      exit (1);
    }

  /* Can fail on an assert */
  mpfr_set_prec (x, 53);
  mpfr_set_str (x, "77291789194529019661184401408", 10, MPFR_RNDN);
  mpfr_init2 (c, 4); mpfr_init2 (s, 42);
  mpfr_init2 (c2, 4); mpfr_init2 (s2, 42);

  test_sin (s, x, MPFR_RNDN);
  mpfr_cos (c, x, MPFR_RNDN);
  mpfr_sin_cos (s2, c2, x, MPFR_RNDN);
  if (mpfr_cmp (c2, c))
    {
      printf("cos differs for x=77291789194529019661184401408");
      exit (1);
    }
  if (mpfr_cmp (s2, s))
    {
      printf("sin differs for x=77291789194529019661184401408");
      exit (1);
    }

  mpfr_set_str_binary (x, "1.1001001000011111101101010100010001000010110100010011");
  test_sin (x, x, MPFR_RNDZ);
  if (mpfr_cmp_str (x, "1.1111111111111111111111111111111111111111111111111111e-1", 2, MPFR_RNDN))
    {
      printf ("Error for x= 1.1001001000011111101101010100010001000010110100010011\nGot ");
      mpfr_dump (x);
      exit (1);
    }

  mpfr_set_prec (s, 9);
  mpfr_set_prec (x, 190);
  mpfr_const_pi (x, MPFR_RNDN);
  mpfr_sin (s, x, MPFR_RNDZ);
  if (mpfr_cmp_str (s, "0.100000101e-196", 2, MPFR_RNDN))
    {
      printf ("Error for x ~= pi\n");
      mpfr_dump (s);
      exit (1);
    }

  mpfr_clear (s2);
  mpfr_clear (c2);
  mpfr_clear (s);
  mpfr_clear (c);
  mpfr_clear (x);

  test_generic (2, 100, 15);
  test_generic (MPFR_SINCOS_THRESHOLD-1, MPFR_SINCOS_THRESHOLD+1, 2);
  test_sign ();
  check_tiny ();

  data_check ("data/sin", mpfr_sin, "mpfr_sin");
  bad_cases (mpfr_sin, mpfr_asin, "mpfr_sin", 256, -40, 0, 4, 128, 800, 50);

  tests_end_mpfr ();
  return 0;
}
Example #6
0
File: tadd.c Project: qsnake/mpfr
static void
tests (void)
{
    check_alloc ();
    check_nans ();
    check_inexact ();
    check_case_1b ();
    check_case_2 ();
    check64();
    coverage_bk_eq_0 ();

    check("293607738.0", "1.9967571564050541e-5", MPFR_RNDU, 64, 53, 53,
          "2.9360773800002003e8");
    check("880524.0", "-2.0769715792901673e-5", MPFR_RNDN, 64, 53, 53,
          "8.8052399997923023e5");
    check("1196426492.0", "-1.4218093058435347e-3", MPFR_RNDN, 64, 53, 53,
          "1.1964264919985781e9");
    check("982013018.0", "-8.941829477291838e-7", MPFR_RNDN, 64, 53, 53,
          "9.8201301799999905e8");
    check("1092583421.0", "1.0880649218158844e9", MPFR_RNDN, 64, 53, 53,
          "2.1806483428158846e9");
    check("1.8476886419022969e-6", "961494401.0", MPFR_RNDN, 53, 64, 53,
          "9.6149440100000179e8");
    check("-2.3222118418069868e5", "1229318102.0", MPFR_RNDN, 53, 64, 53,
          "1.2290858808158193e9");
    check("-3.0399171300395734e-6", "874924868.0", MPFR_RNDN, 53, 64, 53,
          "8.749248679999969e8");
    check("9.064246624706179e1", "663787413.0", MPFR_RNDN, 53, 64, 53,
          "6.6378750364246619e8");
    check("-1.0954322421551264e2", "281806592.0", MPFR_RNDD, 53, 64, 53,
          "2.8180648245677572e8");
    check("5.9836930386056659e-8", "1016217213.0", MPFR_RNDN, 53, 64, 53,
          "1.0162172130000001e9");
    check("-1.2772161928500301e-7", "1237734238.0", MPFR_RNDN, 53, 64, 53,
          "1.2377342379999998e9");
    check("-4.567291988483277e8", "1262857194.0", MPFR_RNDN, 53, 64, 53,
          "8.0612799515167236e8");
    check("4.7719471752925262e7", "196089880.0", MPFR_RNDN, 53, 53, 53,
          "2.4380935175292528e8");
    check("4.7719471752925262e7", "196089880.0", MPFR_RNDN, 53, 64, 53,
          "2.4380935175292528e8");
    check("-1.716113812768534e-140", "1271212614.0", MPFR_RNDZ, 53, 64, 53,
          "1.2712126139999998e9");
    check("-1.2927455200185474e-50", "1675676122.0", MPFR_RNDD, 53, 64, 53,
          "1.6756761219999998e9");

    check53("1.22191250737771397120e+20", "948002822.0", MPFR_RNDN,
            "122191250738719408128.0");
    check53("9966027674114492.0", "1780341389094537.0", MPFR_RNDN,
            "11746369063209028.0");
    check53("2.99280481918991653800e+272", "5.34637717585790933424e+271",
            MPFR_RNDN, "3.5274425367757071711e272");
    check_same();
    check53("6.14384195492641560499e-02", "-6.14384195401037683237e-02",
            MPFR_RNDU, "9.1603877261370314499e-12");
    check53("1.16809465359248765399e+196", "7.92883212101990665259e+196",
            MPFR_RNDU, "9.0969267746123943065e196");
    check53("3.14553393112021279444e-67", "3.14553401015952024126e-67", MPFR_RNDU,
            "6.2910679412797336946e-67");

    check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",MPFR_RNDN,
            "5.4388530464436950905e185");
    check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",MPFR_RNDZ,
            "5.4388530464436944867e185");
    check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",MPFR_RNDU,
            "5.4388530464436950905e185");
    check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",MPFR_RNDD,
            "5.4388530464436944867e185");

    check2b("1.001010101110011000000010100101110010111001010000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e358",187,
            "-1.11100111001101100010001111111110101101110001000000000000000000000000000000000000000000e160",87,
            "1.001010101110011000000010100101110010111001010000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e358",178,
            MPFR_RNDD);
    check2b("-1.111100100011100111010101010101001010100100000111001000000000000000000e481",70,
            "1.1111000110100011110101111110110010010000000110101000000000000000e481",65,
            "-1.001010111111101011010000001100011101100101000000000000000000e472",61,
            MPFR_RNDD);
    check2b("1.0100010111010000100101000000111110011100011001011010000000000000000000000000000000e516",83,
            "-1.1001111000100001011100000001001100110011110010111111000000e541",59,
            "-1.1001111000100001011011110111000001001011100000011110100000110001110011010011000000000000000000000000000000000000000000000000e541",125,
            MPFR_RNDZ);
    check2b("-1.0010111100000100110001011011010000000011000111101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e261",155,
            "-1.00111110100011e239",15,
            "-1.00101111000001001100101010101110001100110001111010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e261",159,
            MPFR_RNDD);
    check2b("-1.110111000011111011000000001001111101101001010100111000000000000000000000000e880",76,
            "-1.1010010e-634",8,
            "-1.11011100001111101100000000100111110110100101010011100000000000000000000000e880",75,
            MPFR_RNDZ);
    check2b("1.00100100110110101001010010101111000001011100100101010000000000000000000000000000e-530",81,
            "-1.101101111100000111000011001010110011001011101001110100000e-908",58,
            "1.00100100110110101001010010101111000001011100100101010e-530",54,
            MPFR_RNDN);
    check2b("1.0101100010010111101000000001000010010010011000111011000000000000000000000000000000000000000000000000000000000000000000e374",119,
            "1.11100101100101e358",15,
            "1.01011000100110011000010110100100100100100110001110110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e374",150,
            MPFR_RNDZ);
    check2b("-1.10011001000010100000010100100110110010011111101111000000000000000000000000000000000000000000000000000000000000000000e-172",117,
            "1.111011100000101010110000100100110100100001001000011100000000e-173",61,
            "-1.0100010000001001010110011011101001001011101011110001000000000000000e-173",68,
            MPFR_RNDZ);
    check2b("-1.011110000111101011100001100110100011100101000011011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-189",175,
            "1.1e631",2,
            "1.011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e631",115,
            MPFR_RNDZ);
    check2b("-1.101011101001011101100011001000001100010100001101011000000000000000000000000000000000000000000e-449",94,
            "-1.01111101010111000011000110011101000111001100110111100000000000000e-429",66,
            "-1.01111101010111000100110010000110100100101111111111101100010100001101011000000000000000000000000000000000000000e-429",111,
            MPFR_RNDU);
    check2b("-1.101011101001011101100011001000001100010100001101011000000000000000000000000000000000000000000e-449",94,
            "-1.01111101010111000011000110011101000111001100110111100000000000000e-429",66,
            "-1.01111101010111000100110010000110100100101111111111101100010100001101011000000000000000000000000000000000000000e-429",111,
            MPFR_RNDD);
    check2b("-1.1001000011101000110000111110010100100101110101111100000000000000000000000000000000000000000000000000000000e-72",107,
            "-1.001100011101100100010101101010101011010010111111010000000000000000000000000000e521",79,
            "-1.00110001110110010001010110101010101101001011111101000000000000000000000000000000000000000000000001e521",99,
            MPFR_RNDD);
    check2b("-1.01010001111000000101010100100100110101011011100001110000000000e498",63,
            "1.010000011010101111000100111100011100010101011110010100000000000e243",64,
            "-1.010100011110000001010101001001001101010110111000011100000000000e498",64,
            MPFR_RNDN);
    check2b("1.00101100010101000011010000011000111111011110010111000000000000000000000000000000000000000000000000000000000e178",108,
            "-1.10101101010101000110011011111001001101111111110000100000000e160",60,
            "1.00101100010100111100100011000011111001000010011101110010000000001111100000000000000000000000000000000000e178",105,
            MPFR_RNDN);
    check2b("1.00110011010100111110011010110100111101110101100100110000000000000000000000000000000000000000000000e559",99,
            "-1.011010110100111011100110100110011100000000111010011000000000000000e559",67,
            "-1.101111111101011111111111001001100100011100001001100000000000000000000000000000000000000000000e556",94,
            MPFR_RNDU);
    check2b("-1.100000111100101001100111011100011011000001101001111100000000000000000000000000e843",79,
            "-1.1101101010110000001001000100001100110011000110110111000000000000000000000000000000000000000000e414",95,
            "-1.1000001111001010011001110111000110110000011010100000e843",53,
            MPFR_RNDD);
    check2b("-1.110110010110100010100011000110111001010000010111110000000000e-415",61,
            "-1.0000100101100001111100110011111111110100011101101011000000000000000000e751",71,
            "-1.00001001011000011111001100111111111101000111011010110e751",54,
            MPFR_RNDN);
    check2b("-1.1011011011110001001101010101001000010100010110111101000000000000000000000e258",74,
            "-1.00011100010110110101001011000100100000100010101000010000000000000000000000000000000000000000000000e268",99,
            "-1.0001110011001001000011110001000111010110101011110010011011110100000000000000000000000000000000000000e268",101,
            MPFR_RNDD);
    check2b("-1.1011101010011101011000000100100110101101101110000001000000000e629",62,
            "1.111111100000011100100011100000011101100110111110111000000000000000000000000000000000000000000e525",94,
            "-1.101110101001110101100000010010011010110110111000000011111111111111111111111111111111111111111111111111101e629",106,
            MPFR_RNDD);
    check2b("1.111001000010001100010000001100000110001011110111011000000000000000000000000000000000000e152",88,
            "1.111110111001100100000100111111010111000100111111001000000000000000e152",67,
            "1.1110111111011110000010101001011011101010000110110100e153",53,
            MPFR_RNDN);
    check2b("1.000001100011110010110000110100001010101101111011110100e696",55,
            "-1.1011001111011100100001011110100101010101110111010101000000000000000000000000000000000000000000000000000000000000e730",113,
            "-1.1011001111011100100001011110100100010100010011100010e730",53,
            MPFR_RNDN);
    check2b("-1.11010111100001001111000001110101010010001111111001100000000000000000000000000000000000000000000000000000000000e530",111,
            "1.01110100010010000000010110111101011101000001111101100000000000000000000000000000000000000000000000e530",99,
            "-1.1000110011110011101010101101111101010011011111000000000000000e528",62,
            MPFR_RNDD);
    check2b("-1.0001100010010100111101101011101000100100010011100011000000000000000000000000000000000000000000000000000000000e733",110,
            "-1.001000000111110010100101010100110111001111011011001000000000000000000000000000000000000000000000000000000000e710",109,
            "-1.000110001001010011111000111110110001110110011000110110e733",55,
            MPFR_RNDN);
    check2b("-1.1101011110000100111100000111010101001000111111100110000000000000000000000e530",74,
            "1.01110100010010000000010110111101011101000001111101100000000000000000000000000000000000000000000000000000000000e530",111,
            "-1.10001100111100111010101011011111010100110111110000000000000000000000000000e528",75,
            MPFR_RNDU);
    check2b("1.00110011010100111110011010110100111101110101100100110000000000000000000000000000000000000000000000e559",99,
            "-1.011010110100111011100110100110011100000000111010011000000000000000e559",67,
            "-1.101111111101011111111111001001100100011100001001100000000000000000000000000000000000000000000e556",94,
            MPFR_RNDU);
    check2b("-1.100101111110110000000110111111011010011101101111100100000000000000e-624",67,
            "1.10111010101110100000010110101000000000010011100000100000000e-587",60,
            "1.1011101010111010000001011010011111110100011110001011111111001000000100101100010010000011100000000000000000000e-587",110,
            MPFR_RNDU);
    check2b("-1.10011001000010100000010100100110110010011111101111000000000000000000000000000000000000000000000000000000000000000000e-172",117,
            "1.111011100000101010110000100100110100100001001000011100000000e-173",61,
            "-1.0100010000001001010110011011101001001011101011110001000000000000000e-173",68,
            MPFR_RNDZ);
    check2b("1.1000111000110010101001010011010011101100010110001001000000000000000000000000000000000000000000000000e167",101,
            "1.0011110010000110000000101100100111000001110110110000000000000000000000000e167",74,
            "1.01100101010111000101001111111111010101110001100111001000000000000000000000000000000000000000000000000000e168",105,
            MPFR_RNDZ);
    check2b("1.100101111111110010100101110111100001110000100001010000000000000000000000000000000000000000000000e808",97,
            "-1.1110011001100000100000111111110000110010100111001011000000000000000000000000000000e807",83,
            "1.01001001100110001100011111000000000001011010010111010000000000000000000000000000000000000000000e807",96,
            MPFR_RNDN);
    check2b("1e128",128,
            "1e0",128,
            "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e0",256,
            MPFR_RNDN);

    /* Checking double precision (53 bits) */
    check53("-8.22183238641455905806e-19", "7.42227178769761587878e-19",MPFR_RNDD,
            "-7.9956059871694317927e-20");
    check53("5.82106394662028628236e+234","-5.21514064202368477230e+89",MPFR_RNDD,
            "5.8210639466202855763e234");
    check53("5.72931679569871602371e+122","-5.72886070363264321230e+122",
            MPFR_RNDN, "4.5609206607281141508e118");
    check53("-5.09937369394650450820e+238", "2.70203299854862982387e+250",
            MPFR_RNDD, "2.7020329985435301323e250");
    check53("-2.96695924472363684394e+27", "1.22842938251111500000e+16",MPFR_RNDD,
            "-2.96695924471135255027e27");
    check53("1.74693641655743793422e-227", "-7.71776956366861843469e-229",
            MPFR_RNDN, "1.669758720920751867e-227");
    /*  x = -7883040437021647.0; for (i=0; i<468; i++) x = x / 2.0;*/
    check53("-1.03432206392780011159e-125", "1.30127034799251347548e-133",
            MPFR_RNDN,
            "-1.0343220509150965661100887242027378881805094180354e-125");
    check53("1.05824655795525779205e+71", "-1.06022698059744327881e+71",MPFR_RNDZ,
            "-1.9804226421854867632e68");
    check53("-5.84204911040921732219e+240", "7.26658169050749590763e+240",
            MPFR_RNDD, "1.4245325800982785854e240");
    check53("1.00944884131046636376e+221","2.33809162651471520268e+215",MPFR_RNDN,
            "1.0094511794020929787e221");
    /*x = 7045852550057985.0; for (i=0; i<986; i++) x = x / 2.0;*/
    check53("4.29232078932667367325e-278",
            "1.0773525047389793833221116707010783793203080117586e-281"
            , MPFR_RNDU, "4.2933981418314132787e-278");
    check53("5.27584773801377058681e-80", "8.91207657803547196421e-91", MPFR_RNDN,
            "5.2758477381028917269e-80");
    check53("2.99280481918991653800e+272", "5.34637717585790933424e+271",
            MPFR_RNDN, "3.5274425367757071711e272");
    check53("4.67302514390488041733e-184", "2.18321376145645689945e-190",
            MPFR_RNDN, "4.6730273271186420541e-184");
    check53("5.57294120336300389254e+71", "2.60596167942024924040e+65", MPFR_RNDZ,
            "5.5729438093246831053e71");
    check53("6.6052588496951015469e24", "4938448004894539.0", MPFR_RNDU,
            "6.6052588546335505068e24");
    check53("1.23056185051606761523e-190", "1.64589756643433857138e-181",
            MPFR_RNDU, "1.6458975676649006598e-181");
    check53("2.93231171510175981584e-280", "3.26266919161341483877e-273",
            MPFR_RNDU, "3.2626694848445867288e-273");
    check53("5.76707395945001907217e-58", "4.74752971449827687074e-51", MPFR_RNDD,
            "4.747530291205672325e-51");
    check53("277363943109.0", "11.0", MPFR_RNDN, "277363943120.0");
    check53("1.44791789689198883921e-140", "-1.90982880222349071284e-121",
            MPFR_RNDN, "-1.90982880222349071e-121");


    /* tests for particular cases (Vincent Lefevre, 22 Aug 2001) */
    check53("9007199254740992.0", "1.0", MPFR_RNDN, "9007199254740992.0");
    check53("9007199254740994.0", "1.0", MPFR_RNDN, "9007199254740996.0");
    check53("9007199254740992.0", "-1.0", MPFR_RNDN, "9007199254740991.0");
    check53("9007199254740994.0", "-1.0", MPFR_RNDN, "9007199254740992.0");
    check53("9007199254740996.0", "-1.0", MPFR_RNDN, "9007199254740996.0");

    check_overflow ();
    check_1111 ();
    check_1minuseps ();
}
Example #7
0
File: tadd.c Project: mahdiz/mpclib
int
main (int argc, char *argv[])
{
#ifdef MPFR_HAVE_FESETROUND
  int prec, rnd_mode;
  int rnd;
  double y;
#endif
  double x;
  int i;

  mpfr_test_init ();
  check_inexact ();
  check_case_1b ();
  check_case_2 ();
  check64();
  check(293607738.0, 1.9967571564050541e-5, GMP_RNDU, 64, 53, 53,
	2.9360773800002003e8);
  check(880524.0, -2.0769715792901673e-5, GMP_RNDN, 64, 53, 53,
	8.8052399997923023e5);
  check(1196426492.0, -1.4218093058435347e-3, GMP_RNDN, 64, 53, 53,
	1.1964264919985781e9);
  check(982013018.0, -8.941829477291838e-7, GMP_RNDN, 64, 53, 53,
	9.8201301799999905e8);
  check(1092583421.0, 1.0880649218158844e9, GMP_RNDN, 64, 53, 53,
	2.1806483428158846e9);
  check(1.8476886419022969e-6, 961494401.0, GMP_RNDN, 53, 64, 53,
	9.6149440100000179e8);
  check(-2.3222118418069868e5, 1229318102.0, GMP_RNDN, 53, 64, 53,
	1.2290858808158193e9);
  check(-3.0399171300395734e-6, 874924868.0, GMP_RNDN, 53, 64, 53,
	8.749248679999969e8);
  check(9.064246624706179e1, 663787413.0, GMP_RNDN, 53, 64, 53,
	6.6378750364246619e8);
  check(-1.0954322421551264e2, 281806592.0, GMP_RNDD, 53, 64, 53,
	2.8180648245677572e8);
  check(5.9836930386056659e-8, 1016217213.0, GMP_RNDN, 53, 64, 53,
	1.0162172130000001e9);
  check(-1.2772161928500301e-7, 1237734238.0, GMP_RNDN, 53, 64, 53,
	1.2377342379999998e9);
  check(-4.567291988483277e8, 1262857194.0, GMP_RNDN, 53, 64, 53,
	8.0612799515167236e8);
  check(4.7719471752925262e7, 196089880.0, GMP_RNDN, 53, 53, 53, 
	2.4380935175292528e8);
  check(4.7719471752925262e7, 196089880.0, GMP_RNDN, 53, 64, 53, 
	2.4380935175292528e8);
  check(-1.716113812768534e-140, 1271212614.0, GMP_RNDZ, 53, 64, 53,
	1.2712126139999998e9);
  check(-1.2927455200185474e-50, 1675676122.0, GMP_RNDD, 53, 64, 53,
	1.6756761219999998e9);
  check53(1.22191250737771397120e+20, 948002822.0, GMP_RNDN, 
	  122191250738719408128.0);
  check53(9966027674114492.0, 1780341389094537.0, GMP_RNDN,
	  11746369063209028.0);
  check53(2.99280481918991653800e+272, 5.34637717585790933424e+271, GMP_RNDN,
	  3.5274425367757071711e272);
  check_same();
  check53(6.14384195492641560499e-02, -6.14384195401037683237e-02, GMP_RNDU,
	  9.1603877261370314499e-12);
  check53(1.16809465359248765399e+196, 7.92883212101990665259e+196, GMP_RNDU,
	  9.0969267746123943065e196);
  check53(3.14553393112021279444e-67, 3.14553401015952024126e-67, GMP_RNDU,
	  6.2910679412797336946e-67);

  SEED_RAND (time(NULL));
  check53(5.43885304644369509058e+185,-1.87427265794105342763e-57,GMP_RNDN,
	  5.4388530464436950905e185);
  check53(5.43885304644369509058e+185,-1.87427265794105342763e-57, GMP_RNDZ,
	  5.4388530464436944867e185);
  check53(5.43885304644369509058e+185,-1.87427265794105342763e-57, GMP_RNDU,
	  5.4388530464436950905e185);
  check53(5.43885304644369509058e+185,-1.87427265794105342763e-57, GMP_RNDD,
	  5.4388530464436944867e185);
  check2a(6.85523243386777784171e+107,187,-2.78148588123699111146e+48,87,178,
	  GMP_RNDD, "4.ab980a5cb9407ffffffffffffffffffffffffffffffe@89");
  check2a(-1.21510626304662318398e+145,70,1.21367733647758957118e+145,65,61,
	 GMP_RNDD, "-1.2bfad031d94@118");
  check2a(2.73028857032080744543e+155,83,-1.16446121423113355603e+163,59,125,
	  GMP_RNDZ, "-3.3c42dee09703d0639a6@135");
  check2a(-4.38589520019641698848e+78,155,-1.09923643769309483415e+72,15,159,
	  GMP_RNDD, "-2.5e09955c663d@65");
  check2a(-1.49963910666191123860e+265,76,-2.30915090591874527520e-191,8,75,
	  GMP_RNDZ, "-1.dc3ec027da54e@220");
  check2a(3.25471707846623300604e-160,81,-7.93846654265839958715e-274,58,54,
	  GMP_RNDN, "4.936a52bc17254@-133");
  check2a(5.17945380930936917508e+112,119,1.11369077158813567738e+108,15,150,
	  GMP_RNDZ, "5.62661692498ec@93");
  check2a(-2.66910493504493276454e-52,117,1.61188644159592323415e-52,61,68,
	  GMP_RNDZ, "-a.204acdd25d788@-44");
  check2a(-1.87427265794105342764e-57,175,1.76570844587489516446e+190,2,115,
	  GMP_RNDZ, "b.fffffffffffffffffffffffffffe@157");
  check2a(-1.15706375390780417299e-135,94,-1.07455137477117851576e-129,66,111,
	  GMP_RNDU, "-b.eae2643497ff6286b@-108");
  check2a(-1.15706375390780417299e-135,94,-1.07455137477117851576e-129,66,111,
	  GMP_RNDD, "-b.eae2643497ff6286b@-108");
  check2a(-3.31624349995221499866e-22,107,-8.20150212714204839621e+156,79,99,
	 GMP_RNDD, "-2.63b22b55697e8000000000008@130");
  x = -5943982715394951.0; for (i=0; i<446; i++) x *= 2.0;
  check2a(x, 63, 1.77607317509426332389e+73, 64, 64, GMP_RNDN,
	  "-5.4781549356e1c@124");
  check2a(4.49465557237618783128e+53,108,-2.45103927353799477871e+48,60,105,
	  GMP_RNDN, "4.b14f230f909dc803e@44");
  check2a(2.26531902208967707071e+168,99,-2.67795218510613988524e+168,67,94,
	GMP_RNDU, "-1.bfd7ff2647098@139");
  check2a(-8.88471912490080158206e+253,79,-7.84488427404526918825e+124,95,53,
	  GMP_RNDD, "-c.1e533b8d835@210");
  check2a(-2.18548638152863831959e-125,61,-1.22788940592412363564e+226,71,54,
	  GMP_RNDN, "-8.4b0f99ffa3b58@187");
  check2a(-7.94156823309993162569e+77,74,-5.26820160805275124882e+80,99,101,
	  GMP_RNDD, "-1.1cc90f11d6af26f4@67");
  check2a(-3.85170653452493859064e+189,62,2.18827389706660314090e+158,94,106,
	  GMP_RNDD, "-3.753ac0935b701ffffffffffffd@157");
  check2a(1.07966151149311101950e+46,88,1.13198076934147457400e+46,67,53,
	  GMP_RNDN, "3.dfbc152dd4368@38");
  check2a(3.36768223223409657622e+209,55,-9.61624007357265441884e+219,113,53,
	  GMP_RNDN, "-6.cf7217a451388@182");
  check2a(-6.47376909368979326475e+159,111,5.11127211034490340501e+159,99,62,
	  GMP_RNDD, "-1.8cf3aadf537c@132");
  check2a(-4.95229483271607845549e+220,110,-6.06992115033276044773e+213,109,55,
	  GMP_RNDN, "-2.3129f1f63b31b@183");
  check2a(-6.47376909368979326475e+159,74,5.11127211034490340501e+159,111,75,
	  GMP_RNDU, "-1.8cf3aadf537c@132");
  check2a(2.26531902208967707070e+168,99,-2.67795218510613988525e+168,67,94,
	 GMP_RNDU, "-1.bfd7ff2647098@139");
  check2a(-2.28886326552077479586e-188,67,3.41419438647157839320e-177,60,110,
	  GMP_RNDU, "3.75740b4fe8f17f90258907@-147");
  check2a(-2.66910493504493276454e-52,117,1.61188644159592323415e-52,61,68,
	  GMP_RNDZ, "-a.204acdd25d788@-44");
  check2a(2.90983392714730768886e+50,101,2.31299792168440591870e+50,74,105,
	 GMP_RNDZ, "1.655c53ff5719c8@42");
  check2a(2.72046257722708717791e+243,97,-1.62158447436486437113e+243,83,96,
	  GMP_RNDN, "a.4cc63e002d2e8@201");
  /* Checking double precision (53 bits) */
  check53(-8.22183238641455905806e-19, 7.42227178769761587878e-19, GMP_RNDD, 
	  -7.9956059871694317927e-20);
  check53(5.82106394662028628236e+234, -5.21514064202368477230e+89, GMP_RNDD,
	  5.8210639466202855763e234);
  check53(5.72931679569871602371e+122, -5.72886070363264321230e+122, GMP_RNDN,
	  4.5609206607281141508e118);
  check53(-5.09937369394650450820e+238, 2.70203299854862982387e+250, GMP_RNDD,
	  2.7020329985435301323e250);
  check53(-2.96695924472363684394e+27, 1.22842938251111500000e+16, GMP_RNDD,
	  -2.96695924471135255027e27);
  check53(1.74693641655743793422e-227, -7.71776956366861843469e-229, GMP_RNDN,
	  1.669758720920751867e-227);
  x = -7883040437021647.0; for (i=0; i<468; i++) x = x / 2.0;
  check53(-1.03432206392780011159e-125, 1.30127034799251347548e-133, GMP_RNDN,
	  x);
  check53(1.05824655795525779205e+71, -1.06022698059744327881e+71, GMP_RNDZ,
	  -1.9804226421854867632e68);
  check53(-5.84204911040921732219e+240, 7.26658169050749590763e+240, GMP_RNDD,
	  1.4245325800982785854e240);
  check53(1.00944884131046636376e+221, 2.33809162651471520268e+215, GMP_RNDN,
	  1.0094511794020929787e221);
  x = 7045852550057985.0; for (i=0; i<986; i++) x = x / 2.0;
  check53(4.29232078932667367325e-278, x, GMP_RNDU,
	  4.2933981418314132787e-278);
  check53(5.27584773801377058681e-80, 8.91207657803547196421e-91, GMP_RNDN,
	  5.2758477381028917269e-80);
  check53(2.99280481918991653800e+272, 5.34637717585790933424e+271, GMP_RNDN,
	  3.5274425367757071711e272);
  check53(4.67302514390488041733e-184, 2.18321376145645689945e-190, GMP_RNDN,
	  4.6730273271186420541e-184);
  check53(5.57294120336300389254e+71, 2.60596167942024924040e+65, GMP_RNDZ,
	  5.5729438093246831053e71);
  check53(6.6052588496951015469e24, 4938448004894539.0, GMP_RNDU,
	6.6052588546335505068e24);
  check53(1.23056185051606761523e-190, 1.64589756643433857138e-181, GMP_RNDU, 
	  1.6458975676649006598e-181);
  check53(2.93231171510175981584e-280, 3.26266919161341483877e-273, GMP_RNDU,
	  3.2626694848445867288e-273);
  check53(5.76707395945001907217e-58, 4.74752971449827687074e-51, GMP_RNDD,
	  4.747530291205672325e-51);
  check53(277363943109.0, 11.0, GMP_RNDN, 277363943120.0);
#if 0         /* disabled since it seems silly to use denorms *
  /* test denormalized numbers too */
  check53(8.06294740693074521573e-310, 6.95250701071929654575e-310, GMP_RNDU,
	  1.5015454417650041761e-309);
#endif
#ifdef HAVE_INFS
  /* the following check double overflow */
  check53(6.27557402141211962228e+307, 1.32141396570101687757e+308,
     GMP_RNDZ, DBL_POS_INF);
  check53(DBL_POS_INF, 6.95250701071929654575e-310, GMP_RNDU, DBL_POS_INF);
  check53(DBL_NEG_INF, 6.95250701071929654575e-310, GMP_RNDU, DBL_NEG_INF);
  check53(6.95250701071929654575e-310, DBL_POS_INF, GMP_RNDU, DBL_POS_INF);
  check53(6.95250701071929654575e-310, DBL_NEG_INF, GMP_RNDU, DBL_NEG_INF);
  check53nan (DBL_POS_INF, DBL_NEG_INF, GMP_RNDN);
#endif
  check53(1.44791789689198883921e-140, -1.90982880222349071284e-121,
	  GMP_RNDN, -1.90982880222349071e-121);


  /* tests for particular cases (Vincent Lefevre, 22 Aug 2001) */
  check53(9007199254740992.0, 1.0, GMP_RNDN, 9007199254740992.0);
  check53(9007199254740994.0, 1.0, GMP_RNDN, 9007199254740996.0);
  check53(9007199254740992.0, -1.0, GMP_RNDN, 9007199254740991.0);
  check53(9007199254740994.0, -1.0, GMP_RNDN, 9007199254740992.0);
  check53(9007199254740996.0, -1.0, GMP_RNDN, 9007199254740996.0);
  
#ifdef MPFR_HAVE_FESETROUND
  prec = (argc<2) ? 53 : atoi(argv[1]);
  rnd_mode = (argc<3) ? -1 : atoi(argv[2]);
  /* Comparing to double precision using machine arithmetic */
  for (i=0;i<N;i++) {
    x = drand(); 
    y = drand();
    if (ABS(x)>2.2e-307 && ABS(y)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
      /* avoid denormalized numbers and overflows */
      rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
      check(x, y, rnd, prec, prec, prec, 0.0);
    }
  } 
  /* tests with random precisions */
  for (i=0;i<N;i++) {
    int px, py, pz;
    px = 53 + (LONG_RAND() % 64); 
    py = 53 + (LONG_RAND() % 64); 
    pz = 53 + (LONG_RAND() % 64); 
    rnd_mode = LONG_RAND() % 4;
    do { x = drand(); } while (isnan(x));
    do { y = drand(); } while (isnan(y));
    check2 (x, px, y, py, pz, rnd_mode);
  }
  /* Checking mpfr_add(x, x, y) with prec=53 */
  for (i=0;i<N;i++) {
    x = drand(); 
    y = drand();
    if (ABS(x)>2.2e-307 && ABS(y)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
      /* avoid denormalized numbers and overflows */
      rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
      check3(x, y, rnd);
    }
  }
  /* Checking mpfr_add(x, y, x) with prec=53 */
  for (i=0;i<N;i++) {
    x = drand(); 
    y = drand();
    if (ABS(x)>2.2e-307 && ABS(y)>2.2e-307 && x+y<1.7e+308 && x+y>-1.7e308) {
      /* avoid denormalized numbers and overflows */
      rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
      check4(x, y, rnd);
    }
  }
  /* Checking mpfr_add(x, x, x) with prec=53 */
  for (i=0;i<N;i++) {
    do { x = drand(); } while ((ABS(x)<2.2e-307) || (ABS(x)>0.8e308));
    /* avoid denormalized numbers and overflows */
    rnd = (rnd_mode==-1) ? LONG_RAND()%4 : rnd_mode;
    check5(x, rnd);
  }
#endif

  return 0;
}
Example #8
0
File: tsin.c Project: mahdiz/mpclib
int
main (int argc, char *argv[])
{
  mpfr_t x;

#ifdef HAVE_INFS
  check53 (DBL_NAN, DBL_NAN, GMP_RNDN);
  check53 (DBL_POS_INF, DBL_NAN, GMP_RNDN);
  check53 (DBL_NEG_INF, DBL_NAN, GMP_RNDN);
#endif
  /* worst case from PhD thesis of Vincent Lefe`vre: x=8980155785351021/2^54 */
  check53 (4.984987858808754279e-1, 4.781075595393330379e-1, GMP_RNDN);
  check53 (4.984987858808754279e-1, 4.781075595393329824e-1, GMP_RNDD);
  check53 (4.984987858808754279e-1, 4.781075595393329824e-1, GMP_RNDZ);
  check53 (4.984987858808754279e-1, 4.781075595393330379e-1, GMP_RNDU);
  check53 (1.00031274099908640274,  8.416399183372403892e-1, GMP_RNDN);
  check53 (1.00229256850978698523,  8.427074524447979442e-1, GMP_RNDZ);
  check53 (1.00288304857059840103,  8.430252033025980029e-1, GMP_RNDZ);
  check53 (1.00591265847407274059,  8.446508805292128885e-1, GMP_RNDN);

  check53 (1.00591265847407274059,  8.446508805292128885e-1, GMP_RNDN);

  mpfr_init2 (x, 2);

  mpfr_set_d (x, 0.5, GMP_RNDN);
  mpfr_sin (x, x, GMP_RNDD);
  if (mpfr_get_d1 (x) != 0.375)
    {
      fprintf (stderr, "mpfr_sin(0.5, GMP_RNDD) failed with precision=2\n");
      exit (1);
    }

  /* bug found by Kevin Ryde */
  mpfr_const_pi (x, GMP_RNDN);
  mpfr_mul_ui (x, x, 3L, GMP_RNDN);
  mpfr_div_ui (x, x, 2L, GMP_RNDN);
  mpfr_sin (x, x, GMP_RNDN);
  if (mpfr_cmp_ui (x, 0) >= 0)
    {
      fprintf (stderr, "Error: wrong sign for sin(3*Pi/2)\n");
      exit (1);
    }

  mpfr_clear (x);

  test_generic (2, 100, 80);

  return 0;
}