Files
virtual-controller/extension-reaper-macos/vendor/reaper-sdk/WDL/cmath/test_eval.c
T
Paul Lipscomb cd5ebd84d6 Add bare-minimum extension-reaper-macos REAPER extension skeleton
C/C++ extension built directly against the vendored Cockos reaper-sdk
headers (no Rust/reaper-rs wrapper layer). Loads, registers a test
action, and confirms via REAPER's console — confirmed working in
REAPER 2026-07-15.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-15 19:12:33 -04:00

88 lines
2.4 KiB
C

/*
test_eval.h
Copyright (C) 2011 and later Lubomir I. Ivanov (neolit123 [at] gmail)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
test horner.h for complex numbers and other related headers
gcc -W -Wall -Wextra -ansi pedantic
cl /W4 /Za
reduced precisions for ansi c
*/
#include "stdio.h"
#include "complex_number.h"
#include "horner.h"
#include "durand_kerner.h"
int main(void)
{
cmath_uint16_t i = 0;
cnum_t y[] = {2, -6, 2, -1};
cnum_s cy[] = {{2, 0}, {-6, 0}, {2, 0}, {-1, 0}};
cnum_t fx = horner_eval(y, 5, poly_order(y));
cnum_s fcx = horner_eval_c(cy, _CNUM(5, 0), poly_order(y));
cnum_t dk_coeff[] = {12, -7, 0.001, 0, 3, -5};
cnum_s dk_roots[5];
cnum_s dk_coeff_c[] = {{12, 0}, {-7, 0}, {0.001, 0}, {0, 0}, {3, 0}, {-5, 0}};
cnum_s dk_roots_c[5];
durand_kerner(dk_coeff, dk_roots, poly_order(dk_coeff));
durand_kerner_c(dk_coeff_c, dk_roots_c, poly_order(dk_coeff_c));
/* */
#ifdef _CMATH_ANSI
puts("\n\nansi c is: on");
#else
puts("\n\nansi c is: off");
#endif
/* */
puts("\n\nevaluate polynomials:\n");
printf("* y[]: %.15f\n", (double)fx);
printf("* cy[]: %.15f \t %.15f*i\n", (double)fcx.r, (double)fcx.i);
/* */
puts("\nfind roots:");
puts("\n* dk_coeff[]:");
i = 0;
while (i < poly_order(dk_coeff))
{
printf("root[%2d]: %.15f \t % .15f*i\n",
i+1, (double)dk_roots[i].r, (double)dk_roots[i].i);
i++;
}
i = 0;
puts("\n* dk_coeff_c[]:");
while (i < poly_order(dk_coeff_c))
{
printf("root[%2d]: %.15f \t % .15f*i\n",
i+1, (double)dk_roots_c[i].r, (double)dk_roots_c[i].i);
i++;
}
return 0;
}