Mercurial > hg > dmlib
view tests/fptest.c @ 2403:6e86a048a760
Adjust help.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 12 Jan 2020 20:53:35 +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; }