📄 simplefloat.c
字号:
/** Simple set of tests for floating pt. */#include <testfwk.h>#include <math.h>#if (PORT_HOST)# define FCOMP(a,b) (fabsf((a) - (b)) < ((b) * 1e-7))#else /* Testing floats for equality is normally a bug, but too keep this test simple we dare it. And it works with the exception of the division on the host port. */# define FCOMP(a,b) ((a) == (b))#endifvoidtestCmp(void){ volatile float left, right; left = 5; right = 13; ASSERT(left + right == 18); ASSERT(left + right <= 18); ASSERT(left + right >= 18); ASSERT(left + right > 17.9); ASSERT(left + right < 18.1);}voidtestDiv(void){#if defined (__mcs51) && !defined (SDCC_STACK_AUTO) idata at 0xd0#endif volatile float left; volatile float right; left = 17; right = 343; ASSERT(FCOMP(left/right, (17.0/343.0))); ASSERT(FCOMP(right/left, (343.0/17.0))); right = 17; ASSERT(FCOMP(left/right, 1.0));}voidtestDivNearOne(void){ volatile float left, right, result; left = 12392.4; right = 12392.4; result = left / right; if (result > 0.999999) { /* Fine */ } else { FAIL(); } if (result < 1.00001) { /* Fine */ } else { FAIL(); } if (result > 0.999999 && result < 1.00001) { /* Fine */ } else { FAIL(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -