Mercurial > hg > dmlib
view tests/fptest.c @ 2576:812b16ee49db
I had been living under apparent false impression that "realfft.c"
on which the FFT implementation in DMLIB was basically copied from
was released in public domain at some point, but it could very well
be that it never was. Correct license is (or seems to be) GNU GPL.
Thus I removing the code from DMLIB, and profusely apologize to the
author, Philip Van Baren.
It was never my intention to distribute code based on his original
work under a more liberal license than originally intended.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 Mar 2022 16:32:50 +0200 |
parents | 88be5cf55caf |
children |
line wrap: on
line source
#include "dmtool.h" #include "dmlib.h" #include <stdio.h> #define FP_DW_SIZE 8 #define FP_W0_SIZE 4 static int test_number = 0; void check(const char *str, DMFixedPoint v, Sint64 dw) { DMFixedPoint *q = (DMFixedPoint *) &dw; printf("%-15s = ", str); FP_PRINTF64(v); printf("\n"); printf("should be = "); FP_PRINTF64((*q)); printf("\n"); if (v.dw != dw) { printf("ERROR! A test value differs from expected!\n"); } } void header(const char *msg) { test_number++; printf("\nTEST #%d: %s\n", test_number, msg); } int main(int argc, char *argv[]) { DMFixedPoint a, b, delta; int i; char *s; (void) argc; (void) argv; // Check host characteristics switch (SDL_BYTEORDER) { case SDL_BIG_ENDIAN: s = "big endian"; break; case SDL_LIL_ENDIAN: s = "little endian"; break; default: s = "unknown?"; break; } printf( "SDL byte order = %s (%d)\n\n", s, SDL_BYTEORDER); printf( "sizeof(DMFixedPoint) = %" DM_PRIu_SIZE_T " bytes\n" "sizeof(DMFixedPoint.dw) = %" DM_PRIu_SIZE_T " bytes (should be %d)\n" "sizeof(DMFixedPoint.w[0]) = %" DM_PRIu_SIZE_T " bytes (should be %d)\n", sizeof(a), sizeof(a.dw), FP_DW_SIZE, sizeof(a.w[0]), FP_W0_SIZE); if (sizeof(a.dw) != FP_DW_SIZE || sizeof(a.w[0]) != FP_W0_SIZE) { printf("ERROR! Some type sizes DO NOT MATCH!\n"); return -1; } //----------------------------------------------- header("set initial values"); FP_SETHL(a, 55, 0); check("a", a, 0x0000003700000000ULL); FP_CONV(b, 178); check("b", b, 0x00000000000000b2ULL); FP_DIV_R(delta, a, b); check("delta", delta, 0x000000004f19e33cULL); //----------------------------------------------- header("50 x (a + delta)"); for (i = 0; i < 50; i++) { FP_ADD(a, delta); } check("a end", a, 0x00000046730e61b8ULL); //----------------------------------------------- header("50 x (a - delta)"); for (i = 0; i < 50; i++) { FP_SUB(a, delta); } check("a end", a, 0x0000003700000000ULL); //----------------------------------------------- header("5 x (a * delta)"); for (i = 0; i < 5; i++) { FP_MUL(a, delta); } check("a end", a, 0xd644e40000000000ULL); //----------------------------------------------- header("a / 2"); FP_CONV(delta, 2); FP_DIV(a, delta); check("a end", a, 0xeb22720000000000ULL); //----------------------------------------------- header("a / 2"); FP_DIV(a, delta); check("a end", a, 0xf591390000000000ULL); //----------------------------------------------- header(""); FP_SETHL(a, -200, 50); FP_CONV(b, 15); FP_DIV(a, b); check("a end", a, 0xfffffff2aaaaaaaeULL); return 0; }