1 /*
2 Copyright (C) 2017 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 "mag.h"
13
14 slong
fmpr_cosh(fmpr_t y,const fmpr_t x,slong prec,fmpr_rnd_t rnd)15 fmpr_cosh(fmpr_t y, const fmpr_t x, slong prec, fmpr_rnd_t rnd)
16 {
17 if (fmpr_is_special(x))
18 {
19 fmpr_add_ui(y, x, 1, prec, rnd);
20 return FMPR_RESULT_EXACT;
21 }
22 else
23 {
24 slong r;
25 CALL_MPFR_FUNC(r, mpfr_cosh, y, x, prec, rnd);
26 return r;
27 }
28 }
29
main()30 int main()
31 {
32 slong iter;
33 flint_rand_t state;
34
35 flint_printf("atan....");
36 fflush(stdout);
37
38 flint_randinit(state);
39
40 for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
41 {
42 fmpr_t x, y, z, z2;
43 mag_t xb, yb;
44
45 fmpr_init(x);
46 fmpr_init(y);
47 fmpr_init(z);
48 fmpr_init(z2);
49
50 mag_init(xb);
51 mag_init(yb);
52
53 mag_randtest_special(xb, state, 0);
54 mag_mul_2exp_si(xb, xb, -100 + n_randint(state,120));
55 mag_randtest_special(yb, state, 25);
56
57 mag_cosh(yb, xb);
58
59 mag_get_fmpr(x, xb);
60 mag_get_fmpr(y, yb);
61
62 fmpr_cosh(z, x, MAG_BITS, FMPR_RND_UP);
63 fmpr_mul_ui(z2, z, 1025, MAG_BITS, FMPR_RND_UP);
64 fmpr_mul_2exp_si(z2, z2, -10);
65
66 MAG_CHECK_BITS(xb)
67 MAG_CHECK_BITS(yb)
68
69 if (!(fmpr_cmpabs(z, y) <= 0 && fmpr_cmpabs(y, z2) <= 0))
70 {
71 flint_printf("FAIL\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("z = "); fmpr_print(z); flint_printf("\n\n");
75 flint_printf("z2 = "); fmpr_print(z2); flint_printf("\n\n");
76 flint_abort();
77 }
78
79 mag_cosh(xb, xb);
80
81 if (!mag_equal(xb, yb))
82 {
83 flint_printf("FAIL (aliasing)\n\n");
84 flint_abort();
85 }
86
87 fmpr_clear(x);
88 fmpr_clear(y);
89 fmpr_clear(z);
90 fmpr_clear(z2);
91
92 mag_clear(xb);
93 mag_clear(yb);
94 }
95
96 flint_randclear(state);
97 flint_cleanup();
98 flint_printf("PASS\n");
99 return EXIT_SUCCESS;
100 }
101
102