1*90a8ff21Smrg /* mpcheck-longdouble -- compare mpc functions against "long double complex"
2*90a8ff21Smrg from the GNU libc implementation
3*90a8ff21Smrg
4*90a8ff21Smrg Copyright (C) 2020 INRIA
5*90a8ff21Smrg
6*90a8ff21Smrg This file is part of GNU MPC.
7*90a8ff21Smrg
8*90a8ff21Smrg GNU MPC is free software; you can redistribute it and/or modify it under
9*90a8ff21Smrg the terms of the GNU Lesser General Public License as published by the
10*90a8ff21Smrg Free Software Foundation; either version 3 of the License, or (at your
11*90a8ff21Smrg option) any later version.
12*90a8ff21Smrg
13*90a8ff21Smrg GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
14*90a8ff21Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15*90a8ff21Smrg FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16*90a8ff21Smrg more details.
17*90a8ff21Smrg
18*90a8ff21Smrg You should have received a copy of the GNU Lesser General Public License
19*90a8ff21Smrg along with this program. If not, see http://www.gnu.org/licenses/ .
20*90a8ff21Smrg */
21*90a8ff21Smrg
22*90a8ff21Smrg /* the GNU libc provides the following functions (as of 2.31),
23*90a8ff21Smrg with 'f' suffix for the float/binary32 version, with no suffix
24*90a8ff21Smrg for the double/binary64 version, with 'l' suffix for the long double
25*90a8ff21Smrg version, and with 'f128' suffix for the __float128 version:
26*90a8ff21Smrg
27*90a8ff21Smrg cabs casinh cexp csinh
28*90a8ff21Smrg cacos catan clog csqrt
29*90a8ff21Smrg cacosh catanh clog10 ctan
30*90a8ff21Smrg carg ccos cpow ctanh
31*90a8ff21Smrg casin ccosh csin
32*90a8ff21Smrg */
33*90a8ff21Smrg
34*90a8ff21Smrg #define _GNU_SOURCE /* for clog10 */
35*90a8ff21Smrg #include <stdio.h>
36*90a8ff21Smrg #include <stdlib.h>
37*90a8ff21Smrg #include <string.h>
38*90a8ff21Smrg #include <complex.h>
39*90a8ff21Smrg #include <sys/types.h>
40*90a8ff21Smrg #include <unistd.h>
41*90a8ff21Smrg #include <assert.h>
42*90a8ff21Smrg #include "mpc.h"
43*90a8ff21Smrg #ifdef __GNUC__
44*90a8ff21Smrg #include <gnu/libc-version.h>
45*90a8ff21Smrg #endif
46*90a8ff21Smrg
47*90a8ff21Smrg #define PRECISION 64
48*90a8ff21Smrg #define EMAX 16384
49*90a8ff21Smrg #define TYPE long double
50*90a8ff21Smrg #define SUFFIX l
51*90a8ff21Smrg
52*90a8ff21Smrg #define mpc_get_type mpc_get_ldc
53*90a8ff21Smrg #define mpc_set_type mpc_set_ldc
54*90a8ff21Smrg #define mpfr_set_type mpfr_set_ld
55*90a8ff21Smrg
56*90a8ff21Smrg gmp_randstate_t state;
57*90a8ff21Smrg mpz_t expz; /* global variable used in mpcheck_random */
58*90a8ff21Smrg unsigned long seed = 0;
59*90a8ff21Smrg int verbose = 0;
60*90a8ff21Smrg mpfr_exp_t emin, emax;
61*90a8ff21Smrg
62*90a8ff21Smrg #include "mpcheck-common.c"
63*90a8ff21Smrg
64*90a8ff21Smrg #define FOO add
65*90a8ff21Smrg #define CFOO(x,y) (x+y)
66*90a8ff21Smrg #include "mpcheck-template3.c"
67*90a8ff21Smrg
68*90a8ff21Smrg #define FOO sub
69*90a8ff21Smrg #define CFOO(x,y) (x-y)
70*90a8ff21Smrg #include "mpcheck-template3.c"
71*90a8ff21Smrg
72*90a8ff21Smrg #define FOO mul
73*90a8ff21Smrg #define CFOO(x,y) (x*y)
74*90a8ff21Smrg #include "mpcheck-template3.c"
75*90a8ff21Smrg
76*90a8ff21Smrg #define FOO div
77*90a8ff21Smrg #define CFOO(x,y) (x/y)
78*90a8ff21Smrg #include "mpcheck-template3.c"
79*90a8ff21Smrg
80*90a8ff21Smrg #define FOO pow
81*90a8ff21Smrg #include "mpcheck-template3.c"
82*90a8ff21Smrg
83*90a8ff21Smrg #define FOO abs
84*90a8ff21Smrg #include "mpcheck-template2.c"
85*90a8ff21Smrg
86*90a8ff21Smrg #define FOO arg
87*90a8ff21Smrg #include "mpcheck-template2.c"
88*90a8ff21Smrg
89*90a8ff21Smrg #define FOO sqrt
90*90a8ff21Smrg #include "mpcheck-template1.c"
91*90a8ff21Smrg
92*90a8ff21Smrg #define FOO acos
93*90a8ff21Smrg #include "mpcheck-template1.c"
94*90a8ff21Smrg
95*90a8ff21Smrg #define FOO acosh
96*90a8ff21Smrg #include "mpcheck-template1.c"
97*90a8ff21Smrg
98*90a8ff21Smrg #define FOO asin
99*90a8ff21Smrg #include "mpcheck-template1.c"
100*90a8ff21Smrg
101*90a8ff21Smrg #define FOO asinh
102*90a8ff21Smrg #include "mpcheck-template1.c"
103*90a8ff21Smrg
104*90a8ff21Smrg #define FOO atan
105*90a8ff21Smrg #include "mpcheck-template1.c"
106*90a8ff21Smrg
107*90a8ff21Smrg #define FOO atanh
108*90a8ff21Smrg #include "mpcheck-template1.c"
109*90a8ff21Smrg
110*90a8ff21Smrg #define FOO cos
111*90a8ff21Smrg #include "mpcheck-template1.c"
112*90a8ff21Smrg
113*90a8ff21Smrg #define FOO cosh
114*90a8ff21Smrg #include "mpcheck-template1.c"
115*90a8ff21Smrg
116*90a8ff21Smrg #define FOO exp
117*90a8ff21Smrg #include "mpcheck-template1.c"
118*90a8ff21Smrg
119*90a8ff21Smrg #define FOO log
120*90a8ff21Smrg #include "mpcheck-template1.c"
121*90a8ff21Smrg
122*90a8ff21Smrg #define FOO log10
123*90a8ff21Smrg #include "mpcheck-template1.c"
124*90a8ff21Smrg
125*90a8ff21Smrg #define FOO sin
126*90a8ff21Smrg #include "mpcheck-template1.c"
127*90a8ff21Smrg
128*90a8ff21Smrg #define FOO sinh
129*90a8ff21Smrg #include "mpcheck-template1.c"
130*90a8ff21Smrg
131*90a8ff21Smrg #define FOO tan
132*90a8ff21Smrg #include "mpcheck-template1.c"
133*90a8ff21Smrg
134*90a8ff21Smrg #define FOO tanh
135*90a8ff21Smrg #include "mpcheck-template1.c"
136*90a8ff21Smrg
137*90a8ff21Smrg int
main(int argc,char * argv[])138*90a8ff21Smrg main (int argc, char *argv[])
139*90a8ff21Smrg {
140*90a8ff21Smrg mpfr_prec_t p = PRECISION; /* precision of 'double' */
141*90a8ff21Smrg unsigned long n = 1000000; /* default number of random tests per function */
142*90a8ff21Smrg
143*90a8ff21Smrg while (argc >= 2 && argv[1][0] == '-')
144*90a8ff21Smrg {
145*90a8ff21Smrg if (argc >= 3 && strcmp (argv[1], "-p") == 0)
146*90a8ff21Smrg {
147*90a8ff21Smrg p = atoi (argv[2]);
148*90a8ff21Smrg argc -= 2;
149*90a8ff21Smrg argv += 2;
150*90a8ff21Smrg }
151*90a8ff21Smrg else if (argc >= 3 && strcmp (argv[1], "-seed") == 0)
152*90a8ff21Smrg {
153*90a8ff21Smrg seed = atoi (argv[2]);
154*90a8ff21Smrg argc -= 2;
155*90a8ff21Smrg argv += 2;
156*90a8ff21Smrg }
157*90a8ff21Smrg else if (argc >= 3 && strcmp (argv[1], "-num") == 0)
158*90a8ff21Smrg {
159*90a8ff21Smrg n = atoi (argv[2]);
160*90a8ff21Smrg argc -= 2;
161*90a8ff21Smrg argv += 2;
162*90a8ff21Smrg }
163*90a8ff21Smrg else if (strcmp (argv[1], "-v") == 0)
164*90a8ff21Smrg {
165*90a8ff21Smrg verbose ++;
166*90a8ff21Smrg argc --;
167*90a8ff21Smrg argv ++;
168*90a8ff21Smrg }
169*90a8ff21Smrg else if (strcmp (argv[1], "-check") == 0)
170*90a8ff21Smrg {
171*90a8ff21Smrg recheck = 1;
172*90a8ff21Smrg argc --;
173*90a8ff21Smrg argv ++;
174*90a8ff21Smrg }
175*90a8ff21Smrg else
176*90a8ff21Smrg {
177*90a8ff21Smrg fprintf (stderr, "Unknown option %s\n", argv[1]);
178*90a8ff21Smrg exit (1);
179*90a8ff21Smrg }
180*90a8ff21Smrg }
181*90a8ff21Smrg
182*90a8ff21Smrg /* set exponent range */
183*90a8ff21Smrg emin = -EMAX - PRECISION + 4; /* should be -16444 */
184*90a8ff21Smrg emax = EMAX;
185*90a8ff21Smrg mpfr_set_emin (emin);
186*90a8ff21Smrg mpfr_set_emax (emax);
187*90a8ff21Smrg
188*90a8ff21Smrg gmp_randinit_default (state);
189*90a8ff21Smrg mpz_init (expz);
190*90a8ff21Smrg
191*90a8ff21Smrg printf ("Using GMP %s, MPFR %s\n", gmp_version, mpfr_get_version ());
192*90a8ff21Smrg
193*90a8ff21Smrg #ifdef __GNUC__
194*90a8ff21Smrg printf ("GNU libc version: %s\n", gnu_get_libc_version ());
195*90a8ff21Smrg printf ("GNU libc release: %s\n", gnu_get_libc_release ());
196*90a8ff21Smrg #endif
197*90a8ff21Smrg
198*90a8ff21Smrg if (seed == 0)
199*90a8ff21Smrg seed = getpid ();
200*90a8ff21Smrg printf ("Using random seed %lu\n", seed);
201*90a8ff21Smrg
202*90a8ff21Smrg /* (complex,complex) -> complex */
203*90a8ff21Smrg test_add (p, n);
204*90a8ff21Smrg test_sub (p, n);
205*90a8ff21Smrg test_mul (p, n);
206*90a8ff21Smrg test_div (p, n);
207*90a8ff21Smrg test_pow (p, n);
208*90a8ff21Smrg
209*90a8ff21Smrg /* complex -> real */
210*90a8ff21Smrg test_abs (p, n);
211*90a8ff21Smrg test_arg (p, n);
212*90a8ff21Smrg
213*90a8ff21Smrg /* complex -> complex */
214*90a8ff21Smrg test_sqrt (p, n);
215*90a8ff21Smrg test_acos (p, n);
216*90a8ff21Smrg test_acosh (p, n);
217*90a8ff21Smrg test_asin (p, n);
218*90a8ff21Smrg test_asinh (p, n);
219*90a8ff21Smrg test_atan (p, n);
220*90a8ff21Smrg test_atanh (p, n);
221*90a8ff21Smrg test_cos (p, n);
222*90a8ff21Smrg test_cosh (p, n);
223*90a8ff21Smrg test_exp (p, n);
224*90a8ff21Smrg test_log (p, n);
225*90a8ff21Smrg test_log10 (p, n);
226*90a8ff21Smrg test_sin (p, n);
227*90a8ff21Smrg test_sinh (p, n);
228*90a8ff21Smrg test_tan (p, n);
229*90a8ff21Smrg test_tanh (p, n);
230*90a8ff21Smrg
231*90a8ff21Smrg gmp_randclear (state);
232*90a8ff21Smrg mpz_clear (expz);
233*90a8ff21Smrg
234*90a8ff21Smrg report_maximal_errors ();
235*90a8ff21Smrg
236*90a8ff21Smrg return 0;
237*90a8ff21Smrg }
238