1 /*
2     Copyright (C) 2013 Fredrik Johansson
3 
4     This file is part of Arb.
5 
6     Arb is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include "fmpr.h"
13 
main()14 int main()
15 {
16     slong iter;
17     flint_rand_t state;
18 
19     flint_printf("set_round_uiui_2exp_fmpz....");
20     fflush(stdout);
21 
22     flint_randinit(state);
23 
24     for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
25     {
26         slong prec, ret1, ret2;
27         fmpz_t man, exp;
28         fmpr_t x, y;
29         mp_limb_t hi, lo;
30         fmpr_rnd_t rnd;
31         int negative;
32 
33         fmpz_init(man);
34         fmpz_init(exp);
35         fmpr_init(x);
36         fmpr_init(y);
37 
38         prec = 2 + n_randint(state, 1000);
39         if (n_randint(state, 10) == 0)
40             prec = FMPR_PREC_EXACT;
41 
42         negative = n_randint(state, 2);
43         hi = n_randtest(state);
44         lo = n_randtest(state);
45         fmpz_randtest(exp, state, 1 + n_randint(state, 100));
46         if (negative)
47             fmpz_neg_uiui(man, hi, lo);
48         else
49             fmpz_set_uiui(man, hi, lo);
50 
51         switch (n_randint(state, 4))
52         {
53             case 0: rnd = FMPR_RND_DOWN; break;
54             case 1: rnd = FMPR_RND_UP; break;
55             case 2: rnd = FMPR_RND_FLOOR; break;
56             default: rnd = FMPR_RND_CEIL; break;
57         }
58 
59         ret1 = fmpr_set_round_uiui_2exp_fmpz(x, hi, lo, exp, negative, prec, rnd);
60 
61         fmpr_set_fmpz_2exp(y, man, exp);
62         ret2 = fmpr_set_round(y, y, prec, rnd);
63 
64         if (!fmpr_equal(x, y) || ret1 != ret2 ||
65             !fmpr_check_ulp(x, ret1, prec) || !fmpr_check_ulp(y, ret2, prec))
66         {
67             flint_printf("FAIL\n\n");
68             flint_printf("prec: %wd\n", prec);
69             flint_printf("hi = %wu, lo = %wu\n", hi, lo);
70             flint_printf("man = "); fmpz_print(man); flint_printf("\n\n");
71             flint_printf("exp = "); fmpz_print(exp); flint_printf("\n\n");
72             flint_printf("x = "); fmpr_print(x); flint_printf("\n\n");
73             flint_printf("y = "); fmpr_print(y); flint_printf("\n\n");
74             flint_printf("ret1 = %wd, ret2 = %wd\n\n", ret1, ret2);
75             flint_abort();
76         }
77 
78         fmpz_clear(man);
79         fmpz_clear(exp);
80         fmpr_clear(x);
81         fmpr_clear(y);
82     }
83 
84     flint_randclear(state);
85     flint_cleanup();
86     flint_printf("PASS\n");
87     return EXIT_SUCCESS;
88 }
89 
90