1 /*
2 test file for eval
3
4 Copyright (C) 2020 Andreas Enge
5
6 This file is part of the MPFRCX Library.
7
8 The MPFRCX Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12
13 The MPFRCX Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with the MPFRCX library; see the file COPYING.LESSER. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA.
22 */
23
24 #include <stdio.h>
25 #include "mpfrcx.h"
26
27
check_eval(mpfrx_t f,mpfr_t x)28 static void check_eval (mpfrx_t f, mpfr_t x) {
29 /* checks whether evaluation in place works; assumes that the real and
30 imaginary parts of x have the same precision; replaces x by f(x) */
31 mpfr_t r;
32
33 mpfr_init2 (r, mpfr_get_prec (x));
34
35 /* check for difference between normal and in place operation */
36 mpfrx_eval (r, f, x);
37 mpfrx_eval (x, f, x);
38 if (mpfr_cmp (r, x)) {
39 fprintf (stderr, "Error in eval: f(x) yields different values\nf: ");
40 mpfrx_out_str (stderr, 10, 0, f);
41 fprintf (stderr, "\nout of place: ");
42 mpfr_out_str (stderr, 10, 0, r, GMP_RNDN);
43 fprintf (stderr, "\nin place: ");
44 mpfr_out_str (stderr, 10, 0, x, GMP_RNDN);
45 fprintf (stderr, "\n");
46 exit (1);
47 }
48
49 mpfr_clear (r);
50 }
51
52
check_eval_random(gmp_randstate_t state)53 static void check_eval_random (gmp_randstate_t state) {
54 int deg;
55 mpfrx_t f;
56 mpfr_t x;
57
58 mpfrx_init (f, 10, 103);
59 mpfr_init2 (x, 103);
60
61 for (deg = -1; deg <= 1000; deg += 200) {
62 mpfrx_urandom (f, deg, state);
63 mpfr_urandom (x, state, GMP_RNDN);
64 check_eval (f, x);
65 }
66
67 mpfrx_clear (f);
68 mpfr_clear (x);
69 }
70
71
main(void)72 int main (void) {
73 gmp_randstate_t state;
74
75 gmp_randinit_default (state);
76
77 check_eval_random (state);
78
79 return 0;
80 }
81