aboutsummaryrefslogtreecommitdiff
path: root/fixsingen/main.c
diff options
context:
space:
mode:
authorflatmush <flatmush@d3e1167c-abe1-51d5-8199-f9061ebe54e4>2011-02-25 15:32:23 +0000
committerflatmush <flatmush@d3e1167c-abe1-51d5-8199-f9061ebe54e4>2011-02-25 15:32:23 +0000
commit0317f964f43995d26d4a54d2f7d37b686ee5a97b (patch)
tree2d10eca61cc99c0f1895c7e626b2940302d3cd8d /fixsingen/main.c
parent0ecfa08dc392830ab4c52b5c8f26d412575583d4 (diff)
downloadlibfixmath-0317f964f43995d26d4a54d2f7d37b686ee5a97b.tar.gz
Added option to replace sin function with ~384KiB look-up table for fastest and most accurate results.
Added tool to generate sin tables. Tests indicate that using a lut is still ~2.1% out from sinf so it's very possible that our sin function is more accurate than the libmath sinf function on the computer I'm testing with. In which case the accuracy results are offset by that amount.
Diffstat (limited to 'fixsingen/main.c')
-rw-r--r--fixsingen/main.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/fixsingen/main.c b/fixsingen/main.c
new file mode 100644
index 0000000..ce71647
--- /dev/null
+++ b/fixsingen/main.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <math.h>
+#include <libfixmath/fixmath.h>
+
+int main(int argc, char** argv) {
+ FILE* fp = fopen("fix16_trig_sin_lut.h", "wb");
+ if(fp == NULL) {
+ fprintf(stderr, "Error: Unable to open file for writing.\n");
+ return EXIT_FAILURE;
+ }
+
+ fprintf(fp, "#ifndef __fix16_trig_sin_lut_h__\n");
+ fprintf(fp, "#define __fix16_trig_sin_lut_h__\n");
+ fprintf(fp, "\n");
+
+ fprintf(fp, "static fix16_t _fix16_sin_lut[%"PRIi32"] = {", (fix16_pi >> 1));
+
+ uintptr_t i;
+ for(i = 0; i < (fix16_pi >> 1); i++) {
+ if((i & 7) == 0)
+ fprintf(fp, "\n\t");
+ fix16_t fix16_sin_lut = fix16_from_dbl(sin(fix16_to_dbl(i)));
+ fprintf(fp, "%"PRIi32", ", fix16_sin_lut);
+ }
+ fprintf(fp, "\n\t};\n");
+
+ fprintf(fp, "\n");
+ fprintf(fp, "#endif\n");
+
+ fclose(fp);
+
+ return EXIT_SUCCESS;
+}