1 /*
2 Copyright (C) 2011 Fredrik Johansson
3
4 This file is part of FLINT.
5
6 FLINT 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 <stdio.h>
13 #include <stdlib.h>
14 #include <math.h>
15 #include <gmp.h>
16 #include "flint.h"
17 #include "ulong_extras.h"
18 #include "fmpz.h"
19
20 int
main(void)21 main(void)
22 {
23 int i, result;
24 FLINT_TEST_INIT(state);
25
26 flint_printf("get_d....");
27 fflush(stdout);
28
29
30
31 for (i = 0; i < 1000 * flint_test_multiplier(); i++)
32 {
33 fmpz_t x, y;
34 mpz_t z;
35 double a, b;
36
37 fmpz_init(x);
38 fmpz_init(y);
39 mpz_init(z);
40
41 fmpz_randtest(x, state, 200);
42 fmpz_get_mpz(z, x);
43
44 a = fmpz_get_d(x);
45 b = mpz_get_d(z);
46
47 result = (a == b);
48 if (!result)
49 {
50 flint_printf("FAIL:\n");
51 flint_printf("x = "), fmpz_print(x), flint_printf("\n");
52 flint_printf("a = %f\n", a);
53 flint_printf("b = %f\n", b);
54 abort();
55 }
56
57 a = a * (n_randtest(state) / (double) n_randtest_not_zero(state));
58
59 fmpz_set_d(x, a);
60 mpz_set_d(z, a);
61
62 fmpz_set_mpz(y, z);
63 result = fmpz_equal(x, y);
64
65 if (!result)
66 {
67 flint_printf("FAIL:\n");
68 flint_printf("x = "), fmpz_print(x), flint_printf("\n");
69 flint_printf("y = "), fmpz_print(y), flint_printf("\n");
70 flint_printf("a = %f\n", a);
71 abort();
72 }
73
74 fmpz_clear(x);
75 fmpz_clear(y);
76 mpz_clear(z);
77 }
78
79 FLINT_TEST_CLEANUP(state);
80
81 flint_printf("PASS\n");
82 return 0;
83 }
84