diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-03-22 23:00:17 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-03-22 23:00:17 +0100 |
commit | c29b044bf5cc874782b0fece6399768b66e5c43b (patch) | |
tree | d65ca07d6939e8be1af508cbd87c1c30c680f00b /inf | |
parent | učenje biologije (diff) | |
download | sola-gimb-3-c29b044bf5cc874782b0fece6399768b66e5c43b.tar sola-gimb-3-c29b044bf5cc874782b0fece6399768b66e5c43b.tar.gz sola-gimb-3-c29b044bf5cc874782b0fece6399768b66e5c43b.tar.bz2 sola-gimb-3-c29b044bf5cc874782b0fece6399768b66e5c43b.tar.lz sola-gimb-3-c29b044bf5cc874782b0fece6399768b66e5c43b.tar.xz sola-gimb-3-c29b044bf5cc874782b0fece6399768b66e5c43b.tar.zst sola-gimb-3-c29b044bf5cc874782b0fece6399768b66e5c43b.zip |
Diffstat (limited to 'inf')
-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; +} |