ulps: Fix long lines
[mathlib.git] / ulps / gen.c
CommitLineData
4be0a29b 1#define _XOPEN_SOURCE 600
2
1437b786 3#include <assert.h>
4be0a29b 4#include <math.h>
5#include <stdio.h>
6#include <string.h>
7
8#include <gmp.h>
5226af1e 9#include <mpc.h>
4be0a29b 10#include <mpfr.h>
11
cb9c014a 12#include "basic-complex.h"
32adbb0c 13#include "config.h"
4be0a29b 14#include "gen.h"
5226af1e 15#include "mytypes.h"
4be0a29b 16
969e5fa8
SK
17/*******************************************************************************
18 * Real arithmetic
19 ******************************************************************************/
4be0a29b 20static int
4a43ae5a 21dom_acos(long double x)
4be0a29b 22{
23 return (x >= -1.0 && x <= 1.0);
24}
25
26static int
4a43ae5a 27dom_acosh(long double x)
4be0a29b 28{
29 return (x >= 1.0);
30}
31
32static int
4a43ae5a 33dom_asin(long double x)
4be0a29b 34{
35 return (x >= -1.0 && x <= 1.0);
36}
37
38static int
4a43ae5a 39dom_asinh(long double x)
4be0a29b 40{
41 return 1;
42}
43
44static int
4a43ae5a 45dom_atan(long double x)
4be0a29b 46{
4a43ae5a 47 return 1;
94545ea5 48}
49
50static int
e75639fd 51dom_atan2(long double y, long double x)
94545ea5 52{
e75639fd 53 return (fpclassify(x) != FP_ZERO);
4be0a29b 54}
55
56static int
4a43ae5a 57dom_atanh(long double x)
4fb65234
SK
58{
59 return (x > -1.0 && x < 1.0);
60}
61
62static int
4a43ae5a 63dom_cbrt(long double x)
6486002c
SK
64{
65 return 1;
66}
67
68static int
4a43ae5a 69dom_ceil(long double x)
6486002c
SK
70{
71 return 1;
72}
73
74static int
e75639fd 75dom_cos(long double x)
6486002c
SK
76{
77 return 1;
78}
79
80static int
e75639fd 81dom_cosh(long double x)
5301862c
SK
82{
83 return 1;
84}
85
86static int
e75639fd 87dom_erf(long double x)
4be0a29b 88{
89 return 1;
90}
91
92static int
e75639fd 93dom_erfc(long double x)
4be0a29b 94{
95 return 1;
96}
97
98static int
e75639fd 99dom_exp(long double x)
4be0a29b 100{
101 return 1;
102}
103
104static int
e75639fd 105dom_expm1(long double x)
4be0a29b 106{
107 return 1;
108}
109
110static int
e75639fd 111dom_exp2(long double x)
4be0a29b 112{
113 return 1;
114}
115
116static int
e75639fd 117dom_fabs(long double x)
4be0a29b 118{
119 return 1;
120}
121
122static int
e75639fd 123dom_floor(long double x)
4be0a29b 124{
125 return 1;
126}
127
128static int
72eb6cec 129dom_fmod(long double x, long double y)
130{
131 return (fpclassify(y) != FP_ZERO);
132}
133
134static int
e75639fd 135dom_hypot(long double x, long double y)
6486002c
SK
136{
137 return 1;
138}
139
140static int
637c5134 141dom_j0(long double x)
142{
143 return 1;
144}
145
146static int
147dom_j1(long double x)
148{
149 return 1;
150}
151
152static int
4a43ae5a 153dom_log(long double x)
4be0a29b 154{
155 return (x > 0.0);
156}
157
158static int
4a43ae5a 159dom_log1p(long double x)
4be0a29b 160{
161 return (x > -1.0);
162}
163
164static int
4a43ae5a 165dom_log10(long double x)
4be0a29b 166{
167 return (x > 0.0);
168}
169
170static int
4a43ae5a 171dom_log2(long double x)
4be0a29b 172{
173 return (x > 0.0);
174}
175
176static int
4a43ae5a 177dom_remainder(long double x, long double y)
15d399dc 178{
179 return (fpclassify(y) != FP_ZERO);
180}
181
182static int
4a43ae5a 183dom_rint(long double x)
4be0a29b 184{
185 return 1;
186}
187
188static int
0f45e0c8 189dom_round(long double x)
190{
191 return 1;
192}
193
194static int
e75639fd 195dom_sin(long double x)
196{
197 return 1;
198}
199
200static int
4a43ae5a 201dom_sinh(long double x)
4be0a29b 202{
203 return 1;
204}
205
206static int
4a43ae5a 207dom_sqrt(long double x)
4be0a29b 208{
209 return (x >= 0.0);
210}
211
212static int
4a43ae5a 213dom_tan(long double x)
8a4557f3
SK
214{
215 return (fabs(x - M_PI_2) > 1E-10);
216}
217
218static int
4a43ae5a 219dom_tanh(long double x)
4de3fdd4
SK
220{
221 return 1;
222}
223
224static int
4a43ae5a 225dom_pow(long double x, long double y)
4be0a29b 226{
8402c1f4 227 return (x >= 0.0 || (floor(y) == y));
4be0a29b 228}
229
230static int
4a43ae5a 231dom_tgamma(long double x)
36903a1f
SK
232{
233 return (x > 0.0 || (floor(x) != x));
234}
235
236static int
c007d9dd 237dom_trunc(long double x)
238{
239 return 1;
240}
241
242static int
4a43ae5a 243dom_y0(long double x)
4be0a29b 244{
245 return (x > 0.0);
246}
247
248static int
4a43ae5a 249dom_y1(long double x)
4be0a29b 250{
132d50d8 251 return (x > 0.0);
4be0a29b 252}
253
254static int
4a43ae5a 255dom_yn(long double x, long double y)
4be0a29b 256{
132d50d8 257 return (y > 0.0);
4be0a29b 258}
259
5226af1e
SK
260/*******************************************************************************
261 * Complex arithmetic
262 ******************************************************************************/
263static int
40a5eabb
SK
264dom_cabs(long double complex z)
265{
266 return 1;
267}
268
269static int
270dom_cacos(long double complex z)
271{
272 return 1;
273}
274
275static int
c67957e7 276dom_cacosh(long double complex z)
277{
278 return 1;
279}
280
281static int
723f1fd7
SK
282dom_carg(long double complex z)
283{
284 /* XXX */
285 return 1;
286}
287
288static int
c67957e7 289dom_casin(long double complex z)
290{
291 return 1;
292}
293
294static int
295dom_casinh(long double complex z)
296{
297 return 1;
298}
299
300static int
301dom_catan(long double complex z)
302{
303 return 1;
304}
305
306static int
307dom_catanh(long double complex z)
308{
309 return 1;
310}
311
312static int
0da540fe 313dom_ccos(long double complex z)
314{
315 return 1;
316}
317
318static int
40a5eabb
SK
319dom_cexp(long double complex z)
320{
321 return 1;
322}
323
324static int
5226af1e
SK
325dom_clog(long double complex z)
326{
327 long_double_complex ldcz = { .z = z };
328
329 return (fpclassify(ldcz.parts[0]) != FP_ZERO ||
330 fpclassify(ldcz.parts[1]) != FP_ZERO);
331}
332
51b30d33 333static int
926f69bd 334dom_conj(long double complex z)
335{
336 return 1;
337}
338
339static int
9d8b2ff4 340dom_cpow(long double complex z, long double complex w)
c67957e7 341{
342 /* XXX */
343 return 1;
344}
345
346static int
926f69bd 347dom_cproj(long double complex z)
51b30d33
SK
348{
349 return 1;
350}
351
0fcd6f30 352static int
926f69bd 353dom_csin(long double complex z)
8a710f61 354{
355 return 1;
356}
357
358static int
926f69bd 359dom_csinh(long double complex z)
0fcd6f30
SK
360{
361 return 1;
362}
363
0e76dbc1 364static int
926f69bd 365dom_csqrt(long double complex z)
ca833956 366{
ca833956 367 return 1;
368}
369
370static int
926f69bd 371dom_ctan(long double complex z)
0e76dbc1 372{
926f69bd 373 /* XXX */
0e76dbc1 374 return 1;
375}
376
cb9c014a 377/*******************************************************************************
378 * Basic arithmetic of complex numbers
379 ******************************************************************************/
380static int
381dom_cadd(long double complex z, long double complex w)
382{
383 return 1;
384}
385
386static int
387dom_csub(long double complex z, long double complex w)
388{
389 return 1;
390}
391static int
392dom_cmul(long double complex z, long double complex w)
393{
394 return 1;
395}
396static int
397dom_cdiv(long double complex z, long double complex w)
398{
4f727e13 399 long_double_complex ldcw = { .z = w };
400
401 return (fpclassify(ldcw.parts[0]) != FP_ZERO ||
402 fpclassify(ldcw.parts[1]) != FP_ZERO);
cb9c014a 403}
404static int
405dom_cneg(long double complex z)
406{
407 return 1;
408}
409
60b17251 410/*
411 * ISO/IEC 9899:1999 - 6.7.8.10 - Initialization
412 *
413 * If an object that has static storage duration is not initialized explicitly,
414 * then [...] if it has pointer type, it is initialized to a null pointer.
415 *
5e95bb5f
SK
416 * Therefore, we can safely assume that f_namel, f_mpfr or f_mpc is NULL,
417 * if autoconf didn't define the corresponding HAVE_XYZ symbol for us.
60b17251 418 */
e75639fd 419static const struct fentry
4be0a29b 420ftable[] = {
c67957e7 421/*******************************************************************************
969e5fa8 422 * Real arithmetic
c67957e7 423 ******************************************************************************/
4be0a29b 424 /* acos() */
32adbb0c 425#ifdef HAVE_ACOS
4be0a29b 426 {
4be0a29b 427 .f_narg = 1,
e75639fd 428 .f_name = "acos",
24d04885 429 .f_libm_real = acos,
75190056 430#ifdef HAVE_ACOSL
e75639fd 431 .f_namel = "acosl",
24d04885 432 .f_libml_real = acosl,
75190056 433#endif
4be0a29b 434 .f_mpfr = mpfr_acos,
435 .f_u.fp1 = dom_acos
436 },
32adbb0c 437#endif
4be0a29b 438
439 /* acosh() */
32adbb0c 440#ifdef HAVE_ACOSH
4be0a29b 441 {
15d399dc 442 .f_narg = 1,
e75639fd 443 .f_name = "acosh",
24d04885 444 .f_libm_real = acosh,
75190056 445#ifdef HAVE_ACOSHL
e75639fd 446 .f_namel = "acoshl",
24d04885 447 .f_libml_real = acoshl,
75190056 448#endif
15d399dc 449 .f_mpfr = mpfr_acosh,
450 .f_u.fp1 = dom_acosh
451 },
32adbb0c 452#endif
4be0a29b 453
454 /* asin() */
32adbb0c 455#ifdef HAVE_ASIN
4be0a29b 456 {
4be0a29b 457 .f_narg = 1,
e75639fd 458 .f_name = "asin",
24d04885 459 .f_libm_real = asin,
75190056 460#ifdef HAVE_ASINL
e75639fd 461 .f_namel = "asinl",
24d04885 462 .f_libml_real = asinl,
75190056 463#endif
4be0a29b 464 .f_mpfr = mpfr_asin,
465 .f_u.fp1 = dom_asin
466 },
32adbb0c 467#endif
4be0a29b 468
469 /* asinh() */
32adbb0c 470#ifdef HAVE_ASINH
15d399dc 471 {
15d399dc 472 .f_narg = 1,
e75639fd 473 .f_name = "asinh",
24d04885 474 .f_libm_real = asinh,
75190056 475#ifdef HAVE_ASINHL
e75639fd 476 .f_namel = "asinhl",
24d04885 477 .f_libml_real = asinhl,
75190056 478#endif
15d399dc 479 .f_mpfr = mpfr_asinh,
480 .f_u.fp1 = dom_asinh
481 },
32adbb0c 482#endif
4be0a29b 483
484 /* atan() */
32adbb0c 485#ifdef HAVE_ATAN
4be0a29b 486 {
4be0a29b 487 .f_narg = 1,
e75639fd 488 .f_name = "atan",
24d04885 489 .f_libm_real = atan,
75190056 490#ifdef HAVE_ATANL
e75639fd 491 .f_namel = "atanl",
24d04885 492 .f_libml_real = atanl,
75190056 493#endif
4be0a29b 494 .f_mpfr = mpfr_atan,
495 .f_u.fp1 = dom_atan
496 },
32adbb0c 497#endif
e75639fd 498
4be0a29b 499 /* atan2() */
32adbb0c 500#ifdef HAVE_ATAN2
4be0a29b 501 {
4be0a29b 502 .f_narg = 2,
e75639fd 503 .f_name = "atan2",
24d04885 504 .f_libm_real = atan2,
75190056 505#ifdef HAVE_ATAN2L
e75639fd 506 .f_namel = "atan2l",
24d04885 507 .f_libml_real = atan2l,
75190056 508#endif
4be0a29b 509 .f_mpfr = mpfr_atan2,
94545ea5 510 .f_u.fp2 = dom_atan2
4be0a29b 511 },
32adbb0c 512#endif
e75639fd 513
4fb65234 514 /* atanh() */
32adbb0c 515#ifdef HAVE_ATANH
4fb65234 516 {
4fb65234 517 .f_narg = 1,
e75639fd 518 .f_name = "atanh",
24d04885 519 .f_libm_real = atanh,
75190056 520#ifdef HAVE_ATANHL
e75639fd 521 .f_namel = "atanhl",
24d04885 522 .f_libml_real = atanhl,
75190056 523#endif
4fb65234
SK
524 .f_mpfr = mpfr_atanh,
525 .f_u.fp1 = dom_atanh
526 },
32adbb0c 527#endif
4fb65234 528
6486002c 529 /* cbrt() */
32adbb0c 530#ifdef HAVE_CBRT
6486002c 531 {
6486002c 532 .f_narg = 1,
e75639fd 533 .f_name = "cbrt",
24d04885 534 .f_libm_real = cbrt,
75190056 535#ifdef HAVE_CBRTL
e75639fd 536 .f_namel = "cbrtl",
24d04885 537 .f_libml_real = cbrtl,
75190056 538#endif
6486002c
SK
539 .f_mpfr = mpfr_cbrt,
540 .f_u.fp1 = dom_cbrt
541 },
32adbb0c 542#endif
6486002c
SK
543
544 /* ceil() */
32adbb0c 545#ifdef HAVE_CEIL
6486002c
SK
546 {
547 .f_name = "ceil",
548 .f_narg = 1,
24d04885 549 .f_libm_real = ceil,
75190056 550#ifdef HAVE_CEILL
e75639fd 551 .f_namel = "ceill",
24d04885 552 .f_libml_real = ceill,
75190056 553#endif
6486002c
SK
554 .f_mpfr = mpfr_ceil,
555 .f_u.fp1 = dom_ceil
556 },
32adbb0c 557#endif
6486002c 558
4be0a29b 559 /* cos() */
32adbb0c 560#ifdef HAVE_COS
4be0a29b 561 {
4be0a29b 562 .f_narg = 1,
e75639fd 563 .f_name = "cos",
24d04885 564 .f_libm_real = cos,
75190056 565#ifdef HAVE_COSL
e75639fd 566 .f_namel = "cosl",
24d04885 567 .f_libml_real = cosl,
75190056 568#endif
4be0a29b 569 .f_mpfr = mpfr_cos,
570 .f_u.fp1 = dom_cos
571 },
32adbb0c 572#endif
4be0a29b 573
574 /* cosh() */
32adbb0c 575#ifdef HAVE_COSH
4be0a29b 576 {
4be0a29b 577 .f_narg = 1,
e75639fd 578 .f_name = "cosh",
24d04885 579 .f_libm_real = cosh,
75190056 580#ifdef HAVE_COSHL
e75639fd 581 .f_namel = "coshl",
24d04885 582 .f_libml_real = coshl,
75190056 583#endif
4be0a29b 584 .f_mpfr = mpfr_cosh,
585 .f_u.fp1 = dom_cosh
586 },
32adbb0c 587#endif
4be0a29b 588
589 /* exp() */
32adbb0c 590#ifdef HAVE_EXP
4be0a29b 591 {
4be0a29b 592 .f_narg = 1,
e75639fd 593 .f_name = "exp",
24d04885 594 .f_libm_real = exp,
75190056 595#ifdef HAVE_EXPL
e75639fd 596 .f_namel = "expl",
24d04885 597 .f_libml_real = expl,
75190056 598#endif
4be0a29b 599 .f_mpfr = mpfr_exp,
600 .f_u.fp1 = dom_exp
601 },
32adbb0c 602#endif
4be0a29b 603
15d399dc 604 /* expm1() */
32adbb0c 605#ifdef HAVE_EXPM1
15d399dc 606 {
15d399dc 607 .f_narg = 1,
e75639fd 608 .f_name = "expm1",
24d04885 609 .f_libm_real = expm1,
75190056 610#ifdef HAVE_EXPM1L
e75639fd 611 .f_namel = "expm1l",
24d04885 612 .f_libml_real = expm1l,
75190056 613#endif
15d399dc 614 .f_mpfr = mpfr_expm1,
4be0a29b 615 .f_u.fp1 = dom_expm1
15d399dc 616 },
32adbb0c 617#endif
4be0a29b 618
619 /* exp2() */
32adbb0c 620#ifdef HAVE_EXP2
4be0a29b 621 {
4be0a29b 622 .f_narg = 1,
e75639fd 623 .f_name = "exp2",
24d04885 624 .f_libm_real = exp2,
75190056 625#ifdef HAVE_EXP2L
e75639fd 626 .f_namel = "exp2l",
24d04885 627 .f_libml_real = exp2l,
75190056 628#endif
4be0a29b 629 .f_mpfr = mpfr_exp2,
15d399dc 630 .f_u.fp1 = dom_exp2
4be0a29b 631 },
32adbb0c 632#endif
4be0a29b 633
6486002c 634 /* erf() */
32adbb0c 635#ifdef HAVE_ERF
6486002c 636 {
6486002c 637 .f_narg = 1,
e75639fd 638 .f_name = "erf",
24d04885 639 .f_libm_real = erf,
75190056 640#ifdef HAVE_ERFL
e75639fd 641 .f_namel = "erfl",
24d04885 642 .f_libml_real = erfl,
75190056 643#endif
6486002c
SK
644 .f_mpfr = mpfr_erf,
645 .f_u.fp1 = dom_erf
646 },
32adbb0c 647#endif
6486002c 648
4be0a29b 649 /* erfc() */
32adbb0c 650#ifdef HAVE_ERFC
4be0a29b 651 {
4be0a29b 652 .f_narg = 1,
e75639fd 653 .f_name = "erfc",
24d04885 654 .f_libm_real = erfc,
75190056 655#ifdef HAVE_ERFCL
e75639fd 656 .f_namel = "erfcl",
24d04885 657 .f_libml_real = erfcl,
75190056 658#endif
4be0a29b 659 .f_mpfr = mpfr_erfc,
5301862c 660 .f_u.fp1 = dom_erfc
6486002c 661 },
32adbb0c 662#endif
6486002c
SK
663
664 /* fabs() */
32adbb0c 665#ifdef HAVE_FABS
6486002c 666 {
6486002c 667 .f_narg = 1,
e75639fd 668 .f_name = "fabs",
24d04885 669 .f_libm_real = fabs,
75190056 670#ifdef HAVE_FABSL
e75639fd 671 .f_namel = "fabsl",
24d04885 672 .f_libml_real = fabsl,
75190056 673#endif
6486002c
SK
674 .f_mpfr = mpfr_abs,
675 .f_u.fp1 = dom_fabs
676 },
32adbb0c 677#endif
6486002c
SK
678
679 /* floor() */
32adbb0c 680#ifdef HAVE_FLOOR
6486002c 681 {
6486002c 682 .f_narg = 1,
e75639fd 683 .f_name = "floor",
24d04885 684 .f_libm_real = floor,
75190056 685#ifdef HAVE_FLOORL
e75639fd 686 .f_namel = "floorl",
24d04885 687 .f_libml_real = floorl,
75190056 688#endif
6486002c
SK
689 .f_mpfr = mpfr_floor,
690 .f_u.fp1 = dom_floor
4be0a29b 691 },
32adbb0c 692#endif
4be0a29b 693
72eb6cec 694 /* fmod() */
695#ifdef HAVE_FMOD
696 {
697 .f_narg = 2,
698 .f_name = "fmod",
699 .f_libm_real = fmod,
700#ifdef HAVE_FMODL
701 .f_namel = "fmodl",
702 .f_libml_real = fmodl,
703#endif
704 .f_mpfr = mpfr_fmod,
705 .f_u.fp1 = dom_fmod
706 },
707#endif
708
4be0a29b 709 /* hypot() */
32adbb0c 710#ifdef HAVE_HYPOT
4be0a29b 711 {
15d399dc 712 .f_narg = 2,
e75639fd 713 .f_name = "hypot",
24d04885 714 .f_libm_real = hypot,
75190056 715#ifdef HAVE_HYPOTL
e75639fd 716 .f_namel = "hypotl",
24d04885 717 .f_libml_real = hypotl,
75190056 718#endif
15d399dc 719 .f_mpfr = mpfr_hypot,
720 .f_u.fp2 = dom_hypot
4be0a29b 721 },
32adbb0c 722#endif
4be0a29b 723
637c5134 724 /* j0() */
725#ifdef HAVE_J0
726 {
727 .f_narg = 1,
728 .f_name = "j0",
729 .f_libm_real = j0,
730#ifdef HAVE_J0Lxxx
731 .f_namel = "j0l",
732 .f_libml_real = j0l,
733#endif
734 .f_mpfr = mpfr_j0,
735 .f_u.fp2 = dom_j0
736 },
737#endif
738
739 /* j1() */
740#ifdef HAVE_J1
741 {
742 .f_narg = 1,
743 .f_name = "j1",
744 .f_libm_real = j1,
745#ifdef HAVE_J1Lxxx
746 .f_namel = "j1l",
747 .f_libml_real = j1l,
748#endif
749 .f_mpfr = mpfr_j1,
750 .f_u.fp2 = dom_j1
751 },
752#endif
753
754
4be0a29b 755 /* log()*/
32adbb0c 756#ifdef HAVE_LOG
4be0a29b 757 {
4be0a29b 758 .f_narg = 1,
e75639fd 759 .f_name = "log",
24d04885 760 .f_libm_real = log,
75190056 761#ifdef HAVE_LOGL
e75639fd 762 .f_namel = "logl",
24d04885 763 .f_libml_real = logl,
75190056 764#endif
4be0a29b 765 .f_mpfr = mpfr_log,
766 .f_u.fp1 = dom_log
767 },
32adbb0c 768#endif
4be0a29b 769
770 /* log1p() */
32adbb0c 771#ifdef HAVE_LOG1P
4be0a29b 772 {
4be0a29b 773 .f_narg = 1,
e75639fd 774 .f_name = "log1p",
24d04885 775 .f_libm_real = log1p,
75190056 776#ifdef HAVE_LOG1PL
e75639fd 777 .f_namel = "log1pl",
24d04885 778 .f_libml_real = log1pl,
75190056 779#endif
4be0a29b 780 .f_mpfr = mpfr_log1p,
15d399dc 781 .f_u.fp1 = dom_log1p
4be0a29b 782 },
32adbb0c 783#endif
4be0a29b 784
785 /* log10() */
32adbb0c 786#ifdef HAVE_LOG10
4be0a29b 787 {
4be0a29b 788 .f_narg = 1,
e75639fd 789 .f_name = "log10",
24d04885 790 .f_libm_real = log10,
75190056 791#ifdef HAVE_LOG10L
e75639fd 792 .f_namel = "log10l",
24d04885 793 .f_libml_real = log10l,
75190056 794#endif
4be0a29b 795 .f_mpfr = mpfr_log10,
796 .f_u.fp1 = dom_log10
797 },
32adbb0c 798#endif
4be0a29b 799
800 /* log2() */
32adbb0c 801#ifdef HAVE_LOG2
4be0a29b 802 {
4be0a29b 803 .f_narg = 1,
e75639fd 804 .f_name = "log2",
24d04885 805 .f_libm_real = log2,
75190056 806#ifdef HAVE_LOG2L
e75639fd 807 .f_namel = "log2l",
24d04885 808 .f_libml_real = log2l,
75190056 809#endif
4be0a29b 810 .f_mpfr = mpfr_log2,
811 .f_u.fp1 = dom_log2
812 },
32adbb0c 813#endif
4be0a29b 814
15d399dc 815 /* remainder() */
816#ifdef HAVE_REMAINDER
817 {
15d399dc 818 .f_narg = 2,
e75639fd 819 .f_name = "remainder",
24d04885 820 .f_libm_real = remainder,
75190056 821#ifdef HAVE_REMAINDERL
e75639fd 822 .f_namel = "remainderl",
24d04885 823 .f_libml_real = remainderl,
75190056 824#endif
15d399dc 825 .f_mpfr = mpfr_remainder,
826 .f_u.fp2 = dom_remainder
827 },
828#endif
829
4be0a29b 830 /* rint() */
32adbb0c 831#ifdef HAVE_RINT
4be0a29b 832 {
4be0a29b 833 .f_narg = 1,
e75639fd 834 .f_name = "rint",
24d04885 835 .f_libm_real = rint,
75190056 836#ifdef HAVE_RINTL
e75639fd 837 .f_namel = "rintl",
24d04885 838 .f_libml_real = rintl,
75190056 839#endif
4be0a29b 840 .f_mpfr = mpfr_rint,
841 .f_u.fp1 = dom_rint
842 },
32adbb0c 843#endif
4be0a29b 844
0f45e0c8 845 /* round() */
846#ifdef HAVE_ROUND
847 {
848 .f_narg = 1,
849 .f_name = "round",
850 .f_libm_real = round,
851#ifdef HAVE_ROUNDL
852 .f_namel = "roundl",
853 .f_libml_real = roundl,
854#endif
855 .f_mpfr = mpfr_round,
856 .f_u.fp1 = dom_round
857 },
858#endif
859
e75639fd 860 /* sin() */
861#ifdef HAVE_SIN
862 {
863 .f_narg = 1,
864 .f_name = "sin",
24d04885 865 .f_libm_real = sin,
e75639fd 866#ifdef HAVE_SINL
867 .f_namel = "sinl",
24d04885 868 .f_libml_real = sinl,
e75639fd 869#endif
870 .f_mpfr = mpfr_sin,
871 .f_u.fp1 = dom_sin
872 },
873#endif
874
4be0a29b 875 /* sinh() */
32adbb0c 876#ifdef HAVE_SINH
4be0a29b 877 {
4be0a29b 878 .f_narg = 1,
e75639fd 879 .f_name = "sinh",
24d04885 880 .f_libm_real = sinh,
75190056 881#ifdef HAVE_SINHL
e75639fd 882 .f_namel = "sinhl",
24d04885 883 .f_libml_real = sinhl,
75190056 884#endif
4be0a29b 885 .f_mpfr = mpfr_sinh,
886 .f_u.fp1 = dom_sinh
887 },
32adbb0c 888#endif
4be0a29b 889
890 /* sqrt() */
32adbb0c 891#ifdef HAVE_SQRT
4be0a29b 892 {
4be0a29b 893 .f_narg = 1,
e75639fd 894 .f_name = "sqrt",
24d04885 895 .f_libm_real = sqrt,
75190056 896#ifdef HAVE_SQRTL
e75639fd 897 .f_namel = "sqrtl",
24d04885 898 .f_libml_real = sqrtl,
75190056 899#endif
4be0a29b 900 .f_mpfr = mpfr_sqrt,
901 .f_u.fp1 = dom_sqrt
902 },
32adbb0c 903#endif
4be0a29b 904
905 /* pow() */
32adbb0c 906#ifdef HAVE_POW
4be0a29b 907 {
4be0a29b 908 .f_narg = 2,
e75639fd 909 .f_name = "pow",
24d04885 910 .f_libm_real = pow,
75190056 911#ifdef HAVE_POWL
e75639fd 912 .f_namel = "powl",
24d04885 913 .f_libml_real = powl,
75190056 914#endif
4be0a29b 915 .f_mpfr = mpfr_pow,
916 .f_u.fp2 = dom_pow
917 },
32adbb0c 918#endif
4be0a29b 919
8a4557f3
SK
920 /* tan() */
921#ifdef HAVE_TAN
922 {
8a4557f3 923 .f_narg = 1,
e75639fd 924 .f_name = "tan",
24d04885 925 .f_libm_real = tan,
75190056 926#ifdef HAVE_TANL
e75639fd 927 .f_namel = "tanl",
24d04885 928 .f_libml_real = tanl,
75190056 929#endif
8a4557f3
SK
930 .f_mpfr = mpfr_tan,
931 .f_u.fp1 = dom_tan
932 },
933#endif
934
4de3fdd4
SK
935 /* tanh() */
936#ifdef HAVE_TANH
937 {
75190056 938 .f_narg = 1,
e75639fd 939 .f_name = "tanh",
24d04885 940 .f_libm_real = tanh,
75190056 941#ifdef HAVE_TANHL
e75639fd 942 .f_namel = "tanhl",
24d04885 943 .f_libml_real = tanhl,
75190056 944#endif
945 .f_mpfr = mpfr_tanh,
946 .f_u.fp1 = dom_tanh
15d399dc 947 },
4de3fdd4
SK
948#endif
949
36903a1f 950 /* tgamma() */
32adbb0c 951#ifdef HAVE_TGAMMA
36903a1f 952 {
36903a1f 953 .f_narg = 1,
e75639fd 954 .f_name = "tgamma",
24d04885 955 .f_libm_real = tgamma,
75190056 956#ifdef HAVE_TGAMMAL
e75639fd 957 .f_namel = "tgammal",
24d04885 958 .f_libml_real = tgammal,
75190056 959#endif
36903a1f 960 .f_mpfr = mpfr_gamma,
735bf73e 961 .f_u.fp1 = dom_tgamma
36903a1f 962 },
32adbb0c 963#endif
36903a1f 964
c007d9dd 965 /* trunc() */
966#ifdef HAVE_TRUNC
967 {
968 .f_narg = 1,
969 .f_name = "trunc",
970 .f_libm_real = trunc,
971#ifdef HAVE_TGAMMAL
972 .f_namel = "truncl",
973 .f_libml_real = truncl,
974#endif
975 .f_mpfr = mpfr_trunc,
976 .f_u.fp1 = dom_trunc
977 },
978#endif
979
4be0a29b 980 /* y0() */
32adbb0c 981#ifdef HAVE_Y0
4be0a29b 982 {
15d399dc 983 .f_narg = 1,
e75639fd 984 .f_name = "y0",
24d04885 985 .f_libm_real = y0,
15d399dc 986 .f_mpfr = mpfr_y0,
987 .f_u.fp1 = dom_y0
988 },
32adbb0c 989#endif
4be0a29b 990
991 /* y1() */
32adbb0c 992#ifdef HAVE_Y1
4be0a29b 993 {
15d399dc 994 .f_narg = 1,
132d50d8 995 .f_name = "y1",
24d04885 996 .f_libm_real = y1,
4be0a29b 997 .f_mpfr = mpfr_y1,
15d399dc 998 .f_u.fp1 = dom_y1
999 },
32adbb0c
SK
1000#endif
1001
4be0a29b 1002 /* yn() */
7eb9c17b 1003#ifdef HAVE_YNxxx
4be0a29b 1004 {
15d399dc 1005 .f_narg = 2,
132d50d8 1006 .f_name = "yn",
24d04885 1007 .f_libm_real = yn,
4be0a29b 1008 .f_mpfr = mpfr_yn,
15d399dc 1009 .f_u.fp2 = dom_yn
5226af1e
SK
1010 },
1011#endif
1012
1013/*******************************************************************************
1014 * Complex arithmetic
1015 ******************************************************************************/
0da540fe 1016 /* cabs() */
40a5eabb 1017#ifdef HAVE_CABS
0da540fe 1018 {
1019 .f_narg = 1,
1020 .f_name = "cabs",
1021 .f_libm_complex = cabs,
40a5eabb 1022#ifdef HAVE_CABSL
0da540fe 1023 .f_namel = "cabsl",
1024 .f_libml_complex = cabsl,
40a5eabb 1025#endif
0da540fe 1026 .f_mpc = mpc_abs,
1027 .f_uc.fp1 = dom_cabs
1028 },
40a5eabb
SK
1029#endif
1030
0da540fe 1031 /* cacos() */
40a5eabb 1032#ifdef HAVE_CACOS
0da540fe 1033 {
1034 .f_narg = 1,
1035 .f_name = "cacos",
1036 .f_libm_complex = cacos,
c67957e7 1037#ifdef HAVE_CACOSL
0da540fe 1038 .f_namel = "cacosl",
1039 .f_libml_complex = cacosl,
40a5eabb 1040#endif
0da540fe 1041 .f_mpc = mpc_acos,
1042 .f_uc.fp1 = dom_cacos
1043 },
40a5eabb
SK
1044#endif
1045
c67957e7 1046 /* cacosh() */
1047#ifdef HAVE_CACOSH
1048 {
1049 .f_narg = 1,
1050 .f_name = "cacosh",
1051 .f_libm_complex = cacosh,
1052#ifdef HAVE_CACOSHL
1053 .f_namel = "cacoshl",
1054 .f_libml_complex = cacoshl,
1055#endif
1056 .f_mpc = mpc_acosh,
1057 .f_uc.fp1 = dom_cacosh
1058 },
1059#endif
1060
0da540fe 1061 /* carg() */
723f1fd7 1062#ifdef HAVE_CARG
0da540fe 1063 {
1064 .f_narg = 1,
1065 .f_name = "carg",
1066 .f_libm_complex = carg,
723f1fd7 1067#ifdef HAVE_CARGL
0da540fe 1068 .f_namel = "cargl",
1069 .f_libml_complex = cargl,
723f1fd7
SK
1070#endif
1071 .f_mpc = mpc_arg,
0da540fe 1072 .f_uc.fp1 = dom_carg
1073 },
1074#endif
1075
c67957e7 1076 /* casin() */
1077#ifdef HAVE_CASIN
1078 {
1079 .f_narg = 1,
1080 .f_name = "casin",
1081 .f_libm_complex = casin,
1082#ifdef HAVE_CASINL
1083 .f_namel = "casinl",
1084 .f_libml_complex = casinl,
1085#endif
1086 .f_mpc = mpc_asin,
1087 .f_uc.fp1 = dom_casin
1088 },
1089#endif
1090
1091 /* casinh() */
1092#ifdef HAVE_CASINH
1093 {
1094 .f_narg = 1,
1095 .f_name = "casinh",
1096 .f_libm_complex = casinh,
1097#ifdef HAVE_CASINHL
1098 .f_namel = "casinhl",
1099 .f_libml_complex = casinhl,
1100#endif
1101 .f_mpc = mpc_asinh,
1102 .f_uc.fp1 = dom_casinh
1103 },
1104#endif
1105
1106 /* catan() */
1107#ifdef HAVE_CATAN
1108 {
1109 .f_narg = 1,
1110 .f_name = "catan",
1111 .f_libm_complex = catan,
1112#ifdef HAVE_CATANL
1113 .f_namel = "catanl",
1114 .f_libml_complex = catanl,
1115#endif
1116 .f_mpc = mpc_atan,
1117 .f_uc.fp1 = dom_catan
1118 },
1119#endif
1120
1121 /* catanh() */
1122#ifdef HAVE_CATANH
1123 {
1124 .f_narg = 1,
e1df065d 1125 .f_name = "catanh",
c67957e7 1126 .f_libm_complex = catanh,
1127#ifdef HAVE_CATANHL
1128 .f_namel = "catanhl",
1129 .f_libml_complex = catanhl,
1130#endif
1131 .f_mpc = mpc_atanh,
1132 .f_uc.fp1 = dom_catanh
1133 },
1134#endif
1135
0da540fe 1136 /* ccos() */
1137#ifdef HAVE_CCOS
1138 {
1139 .f_narg = 1,
1140 .f_name = "ccos",
1141 .f_libm_complex = ccos,
8a286ecf 1142#ifdef HAVE_CCOSL
0da540fe 1143 .f_namel = "ccosl",
1144 .f_libml_complex = ccosl,
1145#endif
1146 .f_mpc = mpc_cos,
1147 .f_uc.fp1 = dom_ccos
1148 },
723f1fd7
SK
1149#endif
1150
40a5eabb
SK
1151 /* cexp() */
1152#ifdef HAVE_CEXP
0da540fe 1153 {
1154 .f_narg = 1,
1155 .f_name = "cexp",
1156 .f_libm_complex = cexp,
40a5eabb 1157#ifdef HAVE_CEXPL
0da540fe 1158 .f_namel = "cexpl",
1159 .f_libml_complex = cexpl,
40a5eabb 1160#endif
0da540fe 1161 .f_mpc = mpc_exp,
1162 .f_uc.fp1 = dom_cexp
1163 },
40a5eabb
SK
1164#endif
1165
5226af1e
SK
1166 /* clog() */
1167#ifdef HAVE_CLOG
1168 {
5226af1e
SK
1169 .f_narg = 1,
1170 .f_name = "clog",
24d04885 1171 .f_libm_complex = clog,
5226af1e 1172#ifdef HAVE_CLOGL
51b30d33
SK
1173 .f_namel = "clogl",
1174 .f_libml_complex = clogl,
5226af1e
SK
1175#endif
1176 .f_mpc = mpc_log,
1177 .f_uc.fp1 = dom_clog
51b30d33
SK
1178 },
1179#endif
1180
0e76dbc1 1181 /* conj() */
1182#ifdef HAVE_CONJ
1183 {
1184 .f_narg = 1,
1185 .f_name = "conj",
1186 .f_libm_complex = conj,
1187#ifdef HAVE_CONJL
8a710f61 1188 .f_namel = "conjl",
0e76dbc1 1189 .f_libml_complex = conjl,
1190#endif
1191 .f_mpc = mpc_conj,
1192 .f_uc.fp1 = dom_conj
1193 },
1194#endif
1195
c67957e7 1196 /* cpow() */
1197#ifdef HAVE_CPOW
1198 {
a29d0f40 1199 .f_narg = 2,
1200 .f_name = "cpow",
1201 .f_libm_complex = cpow,
c67957e7 1202#ifdef HAVE_CPOWL
a29d0f40 1203 .f_namel = "cpowl",
1204 .f_libml_complex = cpowl,
c67957e7 1205#endif
a29d0f40 1206 .f_mpc = mpc_pow,
1207 .f_uc.fp1 = dom_cpow
c67957e7 1208 },
1209#endif
1210
926f69bd 1211 /* cproj() */
1212#ifdef HAVE_CPROJ
1213 {
1214 .f_narg = 1,
1215 .f_name = "cproj",
1216 .f_libm_complex = cproj,
1217#ifdef HAVE_CPROJL
1218 .f_namel = "cprojl",
1219 .f_libml_complex = cprojl,
1220#endif
1221 .f_mpc = mpc_proj,
1222 .f_uc.fp1 = dom_cproj
1223 },
1224#endif
1225
51b30d33
SK
1226 /* csin() */
1227#ifdef HAVE_CSIN
1228 {
a29d0f40 1229 .f_narg = 1,
1230 .f_name = "csin",
1231 .f_libm_complex = csin,
51b30d33 1232#ifdef HAVE_CSINL
a29d0f40 1233 .f_namel = "csinl",
1234 .f_libml_complex = csinl,
51b30d33 1235#endif
a29d0f40 1236 .f_mpc = mpc_sin,
1237 .f_uc.fp1 = dom_csin
0fcd6f30
SK
1238 },
1239#endif
1240
8a710f61 1241 /* csinh() */
1242#ifdef HAVE_CSINH
1243 {
1244 .f_narg = 1,
1245 .f_name = "csinh",
1246 .f_libm_complex = csinh,
1247#ifdef HAVE_CSINHL
1248 .f_namel = "csinhl",
1249 .f_libml_complex = csinhl,
1250#endif
1251 .f_mpc = mpc_sinh,
1252 .f_uc.fp1 = dom_csinh
1253 },
1254#endif
1255
0fcd6f30
SK
1256 /* csqrt() */
1257#ifdef HAVE_CSQRT
0da540fe 1258 {
0fcd6f30
SK
1259 .f_narg = 1,
1260 .f_name = "csqrt",
1261 .f_libm_complex = csqrt,
1262#ifdef HAVE_CSQRTL
8a710f61 1263 .f_namel = "csqrtl",
0fcd6f30
SK
1264 .f_libml_complex = csqrtl,
1265#endif
1266 .f_mpc = mpc_sqrt,
1267 .f_uc.fp1 = dom_csqrt
7cf93a62 1268 },
1269#endif
1270
1271 /* ctan() */
1272#ifdef HAVE_CTAN
8a710f61 1273 {
a29d0f40 1274 .f_narg = 1,
1275 .f_name = "ctan",
1276 .f_libm_complex = ctan,
7cf93a62 1277#ifdef HAVE_CTANL
a29d0f40 1278 .f_namel = "ctanl",
1279 .f_libml_complex = ctanl,
7cf93a62 1280#endif
a29d0f40 1281 .f_mpc = mpc_tan,
1282 .f_uc.fp1 = dom_ctan
cb9c014a 1283 },
8402c1f4 1284#endif
cb9c014a 1285
1286/*******************************************************************************
1287 * Basic arithmetic of complex numbers
1288 ******************************************************************************/
1289 /* cadd() */
1290 {
1291 .f_narg = 2,
1292 .f_name = "cadd",
1293 .f_libm_complex = cadd,
1294 .f_namel = "caddl",
1295 .f_libml_complex = caddl,
1296 .f_mpc = mpc_add,
1297 .f_uc.fp2 = dom_cadd
1298 },
1299
1300 /* csub() */
1301 {
1302 .f_narg = 2,
1303 .f_name = "csub",
1304 .f_libm_complex = csub,
1305 .f_namel = "csubl",
1306 .f_libml_complex = csubl,
1307 .f_mpc = mpc_sub,
1308 .f_uc.fp2 = dom_csub
1309 },
1310
1311 /* cmul() */
1312 {
1313 .f_narg = 2,
1314 .f_name = "cmul",
1315 .f_libm_complex = cmul,
1316 .f_namel = "cmull",
1317 .f_libml_complex = cmull,
1318 .f_mpc = mpc_mul,
1319 .f_uc.fp2 = dom_cmul
1320 },
1321
1322 /* cdiv() */
1323 {
1324 .f_narg = 2,
1325 .f_name = "cdiv",
1326 .f_libm_complex = cdiv,
1327 .f_namel = "cdivl",
1328 .f_libml_complex = cdivl,
1329 .f_mpc = mpc_div,
1330 .f_uc.fp2 = dom_cdiv
1331 },
1332
1333 /* cneg() */
1334 {
1335 .f_narg = 1,
1336 .f_name = "cneg",
1337 .f_libm_complex = cneg,
1338 .f_namel = "cnegl",
1339 .f_libml_complex = cnegl,
1340 .f_mpc = mpc_neg,
1341 .f_uc.fp2 = dom_cneg
1342 }
4be0a29b 1343};
1344
1437b786 1345const int fsize = sizeof(ftable) / sizeof(ftable[0]);
1346
b0341cf8 1347static void
5226af1e
SK
1348assertfunction(const struct fentry *f)
1349{
1350 assert(f);
51b30d33 1351 assert(f->f_narg == 1 || f->f_narg == 2);
5226af1e 1352 assert(f->f_name);
8a710f61 1353
1354 if (f->f_mpfr) {
5226af1e 1355 assert(f->f_u.fp1 || f->f_u.fp2);
8a710f61 1356 assert(f->f_libm_real);
1357 if (f->f_namel)
1358 assert(f->f_libml_real);
1359 }
1360
1361 if (f->f_mpc) {
5226af1e 1362 assert(f->f_uc.fp1 || f->f_u.fp2);
8a710f61 1363 assert(f->f_libm_complex);
1364 if (f->f_namel)
1365 assert(f->f_libml_complex);
1366 }
1367
5226af1e
SK
1368 assert(f->f_mpfr || f->f_mpc);
1369}
1370
4be0a29b 1371const struct fentry *
da06af21 1372getfunctionbyidx(int idx)
e75639fd 1373{
da06af21 1374 assert(0 <= idx && idx < fsize);
e75639fd 1375
1376 return (&ftable[idx]);
1377}
1378
1379const struct fentry *
b9284fd1 1380getfunctionbyname(const char *fname)
4be0a29b 1381{
993de363 1382 const struct fentry *f;
3e0d1ace 1383 int i;
1437b786 1384
1385 assert(fname);
4be0a29b 1386
1437b786 1387 for (i = 0; i < fsize; i++) {
993de363 1388 f = &ftable[i];
e75639fd 1389 if ((strcmp(fname, f->f_name ) == 0) ||
1390 (f->f_namel && strcmp(fname, f->f_namel) == 0)) {
5226af1e 1391 assertfunction(f);
993de363 1392 return (f);
4be0a29b 1393 }
1394 }
1395
1396 return (NULL);
1397}
a4873c4d
SK
1398
1399void
1400printfunctions(void)
1401{
56ee29e7 1402 const struct fentry *f;
1403 int i, cnt;
a4873c4d 1404
56ee29e7 1405 for (i = 0, cnt = 0; i < fsize; i++, cnt++) {
1406 f = &ftable[i];
1407 printf("%-10s ", f->f_name);
1408 if (cnt % 5 == 4)
1409 printf("\n");
1410 if (f->f_namel) {
1411 cnt++;
1412 printf("%-10s ", f->f_namel);
1413 if (cnt % 5 == 4)
1414 printf("\n");
1415 }
1416 }
c67957e7 1417
1418 /* If cnt % 5 was equal to 4, then now it's equal to 0 */
c36ce6a8 1419 if (cnt % 5 != 0)
56ee29e7 1420 printf("\n");
a4873c4d 1421}