From c29b044bf5cc874782b0fece6399768b66e5c43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 22 Mar 2022 23:00:17 +0100 Subject: pred testom matematike --- inf/razno/complexbench.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 inf/razno/complexbench.c (limited to 'inf') diff --git a/inf/razno/complexbench.c b/inf/razno/complexbench.c new file mode 100644 index 0000000..ceb1129 --- /dev/null +++ b/inf/razno/complexbench.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +struct kompleksno { + long double r; + long double i; +}; +struct kompleksno množi (struct kompleksno a, struct kompleksno b) { + struct kompleksno r; + r.r = (a.r * b.r) - (a.i * b.i /* ii = -1 */); + r.i = (a.i * b.r) + (a.r * b.i); /* zakon o distributivnosti */ + return r; +} +struct kompleksno seštej (struct kompleksno a, struct kompleksno b) { + a.r += b.r; + a.i += b.i; + return a; +} +int main (int argc, char ** argv) { + long double complex c = 0.001 + 0.0001 * I; + struct kompleksno k = { .r = 0.001, .i = 0.0001 }; + long double complex a = -0.5 + 0.55 * I; + struct kompleksno s = { .r = -0.5, .i = 0.55 }; + int število = argc > 1 ? atoi(argv[1]) : 10000; + clock_t cikli = clock(); + for (int i = 0; i < število; i++) { + c = c*c + a; + if (creall(c) > 0.01 && cimagl(c) < -0.02) + c += 0.00003; + } + fprintf(stderr, "rezultat complex.h: %Lf+%Lfi\n", creall(c), cimagl(c)); + fprintf(stderr, " porabljen čas: %ld ciklov\n", clock()-cikli); + cikli = clock(); + for (int i = 0; i < število; i++) { + k = seštej(množi(k, k), s); + if (k.r > 0.01 && k.i < -0.02) + k.r += 0.00003; + } + fprintf(stderr, "rezultat na roke: %Lf+%Lfi\n", k.r, k.i); + fprintf(stderr, " porabljen čas: %ld ciklov\n", clock()-cikli); + return 0; +} -- cgit v1.2.3