diff options
Diffstat (limited to 'inf/razno/complexbench.c')
-rw-r--r-- | inf/razno/complexbench.c | 43 |
1 files changed, 43 insertions, 0 deletions
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 <complex.h> +#include <stdio.h> +#include <time.h> +#include <stdlib.h> +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; +} |