Create FUNDING.yml
[wdl/wdl-ol.git] / WDL / cmath / test_bessel.c
blob83915a6c57a172b77a89076d9c817eeb4aaff3fb
1 /*
2 test_bessel.h
3 Copyright (C) 2011 and later Lubomir I. Ivanov (neolit123 [at] gmail)
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
23 test bessel_polynomial.h and other related headers
25 gcc -W -Wall -Wextra -ansi pedantic
26 cl /W4 /Za
28 reduced precisions for ansi c
31 #include "stdio.h"
32 #include "custom_math.h"
33 #include "bessel_polynomial.h"
34 #include "durand_kerner.h"
36 int main(void)
38 register cmath_uint16_t i = 0;
39 register cmath_int16_t diff = 0;
41 cmath_uint32_t in_order = _BESSEL_MAX_ORDER + 1;
42 cmath_uint16_t order;
43 const cmath_uint16_t reverse = 1;
45 cmath_std_int_t coeff[_BESSEL_MAX_ORDER + 1];
47 cnum_t dk_coeff[_BESSEL_MAX_ORDER + 1];
48 cnum_s dk_roots[_BESSEL_MAX_ORDER];
50 /* */
51 #ifdef _CMATH_ANSI
52 puts("\n\nansi c is: on");
53 #else
54 puts("\n\nansi c is: off");
55 #endif
57 /* */
58 while (in_order > _BESSEL_MAX_ORDER)
60 printf("\nenter order of bessel polynomial (0 - %d): ", _BESSEL_MAX_ORDER);
61 scanf("%u", &in_order);
64 order = (cmath_uint16_t)in_order;
65 bessel_polynomial(coeff, order, reverse);
67 printf("\norder [N]: %d", order);
68 printf("\nreversed bessel: %d\n\n", reverse);
69 printf("list of coefficients:\n");
70 while (i <= order)
72 printf("order[%2d]: ", (order - i));
73 printf("%"_CMATH_PR_STD_INT"\n", coeff[i]);
74 i++;
76 puts("\npolynomial:");
77 printf("y(x) = ");
79 i = 0;
80 while (i <= order)
82 diff = (cmath_int16_t)(order - i);
83 if (diff > 0)
84 if (coeff[i] > 1)
86 printf("%"_CMATH_PR_STD_INT, coeff[i]);
87 if (diff > 1)
88 printf("*x^%d + ", diff);
89 else
90 printf("*x + ");
92 else
93 printf("x^%d + ", diff);
94 else
95 printf("%"_CMATH_PR_STD_INT"", coeff[i]);
96 i++;
99 /* */
100 puts("\n\nlist roots:");
101 i = 0;
102 while (i < order+1)
104 dk_coeff[i] = (cnum_t)coeff[i];
105 i++;
108 durand_kerner(dk_coeff, dk_roots, order);
110 i = 0;
111 while (i < order)
113 printf("root[%2d]: %.15f \t % .15f*i\n",
114 i+1, (double)dk_roots[i].r, (double)dk_roots[i].i);
115 i++;
118 return 0;