libdgl/TEST/FIXED.C
Gered 62af8575c6 various updates i've left uncommitted for many months
- rename standard integer types to a more familiar (u)int(8/16/32)
- many function/struct renames. i don't _really_ know if what i've done
  for this is better, but it "feels" better to me. many draw/blit
  function names are shorter which is nice, at least. kinda important
  to me because i develop this on a real DOS machine in 80x50 text mode.
- add 'extern "C"' blocks to headers for C++ compiler usage
- draw/pixel color value arguments for functions should all have been
  changed to be uint8 instead of a full 32-bit int. feels right, but
  maybe should've left alone...
- small fix to keyboard handler. noticed a problem on one thinkpad
  laptop. was a result of what i think was a typo in a constant value
  used during the part of the interrupt handler that tells the keyboard
  controller the key event was processed
- fix uncommon potential crash function return in draw_filled_rect
- renamed low-level "direct" assembly functions to "lowlevel_xxx" to
  be a little bit more explicit about what they are
- add some convenience event helper functions for determining event
  types
- add fixed point atan2
- fixed some tabs/spaces inconsistences (should all be spaces now?)
- maybe some other minor things i've forgotten
2020-07-19 19:24:48 -04:00

75 lines
1.5 KiB
C
Executable file

#include "fixed.h"
#include "dglfixp.h"
#include "dglmath.h"
#include <stdio.h>
#include "helpers.h"
void test_fixed(void) {
fixed a, b, c;
float af, bf, cf, f;
float aaf, bbf, ccf;
int i;
a = FTOFIX(PI);
f = FIXTOF(a);
ASSERT(FFIX_EQU(PI, f));
a = FTOFIX(-0.38f);
f = FIXTOF(a);
ASSERT(FFIX_EQU(-0.38f, f));
a = ITOFIX(17);
i = FIXTOI(a);
ASSERT(17 == i);
a = ITOFIX(-17);
i = FIXTOI(a);
ASSERT(-17 == i);
a = FTOFIX(1.5f);
b = FTOFIX(2.3f);
c = a + b;
f = FIXTOF(c);
ASSERT(FFIX_EQU((1.5f + 2.3f), f));
a = FTOFIX(0.2f);
b = FTOFIX(1.7f);
c = a - b;
f = FIXTOF(c);
ASSERT(FFIX_EQU((0.2f - 1.7f), f));
a = FTOFIX(16.0f);
c = a >> 2;
f = FIXTOF(c);
ASSERT(FFIX_EQU((16 >> 2), f));
a = FTOFIX(7.1f);
b = ITOFIX(2);
c = fix_mul(a, b);
f = FIXTOF(c);
ASSERT(FFIX_EQU((7.1f * 2), f));
a = FTOFIX(77.7f);
b = ITOFIX(3);
c = fix_div(a, b);
f = FIXTOF(c);
ASSERT(FFIX_EQU((77.7f / 3), f));
for (i = 0; i <= 360; i += 45) {
f = DEG_TO_RAD(i + 1);
a = fix_sin(FTOFIX(f));
af = sin(f);
aaf = FIXTOF(a);
b = fix_cos(FTOFIX(f));
bf = cos(f);
bbf = FIXTOF(b);
c = fix_tan(FTOFIX(f));
cf = tan(f);
ccf = FIXTOF(c);
ASSERT(FFIX_EQU(aaf, af));
ASSERT(FFIX_EQU(bbf, bf));
ASSERT(FFIX_EQU(ccf, cf));
}
}