diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2012-08-13 22:10:03 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2012-08-13 22:10:03 +0200 |
commit | 1d029b01fe466b67969d650accf911a75fd620ab (patch) | |
tree | 314df263c4f706552a41be54c2aa2e978a2f5b66 /apps/px4/tests/test_float.c | |
parent | 6fb3bbb5da23454cc9b56cc502b2689572f94a4c (diff) | |
download | px4-firmware-1d029b01fe466b67969d650accf911a75fd620ab.tar.gz px4-firmware-1d029b01fe466b67969d650accf911a75fd620ab.tar.bz2 px4-firmware-1d029b01fe466b67969d650accf911a75fd620ab.zip |
First initial revision of ACC driver and gyro
Diffstat (limited to 'apps/px4/tests/test_float.c')
-rw-r--r-- | apps/px4/tests/test_float.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/apps/px4/tests/test_float.c b/apps/px4/tests/test_float.c index 0439476e6..4922d06b1 100644 --- a/apps/px4/tests/test_float.c +++ b/apps/px4/tests/test_float.c @@ -62,7 +62,7 @@ int test_float(int argc, char *argv[]) int ret = 0; printf("\n--- SINGLE PRECISION TESTS ---\n"); - printf("The single precision test involves calls to fabs(),\nif test fails check this function as well.\n\n"); + printf("The single precision test involves calls to fabsf(),\nif test fails check this function as well.\n\n"); float f1 = 1.55f; @@ -80,7 +80,7 @@ int test_float(int argc, char *argv[]) fflush(stdout); - if (fabs((sinf_one - 0.841470956802368164062500000000f)) < FLT_EPSILON) { + if (fabsf((sinf_one - 0.841470956802368164062500000000f)) < FLT_EPSILON) { printf("\t success: sinf(1.0f) == 0.84147f\n"); } else { @@ -92,7 +92,7 @@ int test_float(int argc, char *argv[]) float asinf_one = asinf(1.0f); - if (fabs((asinf_one - 1.570796251296997070312500000000f)) < FLT_EPSILON * 1.5f) { + if (fabsf((asinf_one - 1.570796251296997070312500000000f)) < FLT_EPSILON * 1.5f) { printf("\t success: asinf(1.0f) == 1.57079f\n"); } else { @@ -104,7 +104,7 @@ int test_float(int argc, char *argv[]) float cosf_one = cosf(1.0f); - if (fabs((cosf_one - 0.540302336215972900390625000000f)) < FLT_EPSILON) { + if (fabsf((cosf_one - 0.540302336215972900390625000000f)) < FLT_EPSILON) { printf("\t success: cosf(1.0f) == 0.54030f\n"); } else { @@ -117,7 +117,7 @@ int test_float(int argc, char *argv[]) float acosf_one = acosf(1.0f); - if (fabs((acosf_one - 0.000000000000000000000000000000f)) < FLT_EPSILON) { + if (fabsf((acosf_one - 0.000000000000000000000000000000f)) < FLT_EPSILON) { printf("\t success: acosf(1.0f) == 0.0f\n"); } else { @@ -162,9 +162,9 @@ int test_float(int argc, char *argv[]) if (sbuf[0] == ' ' && sbuf[1] == ' ' && sbuf[2] == '0' && sbuf[3] == '.' && sbuf[4] == '5' && sbuf[5] == '5' && sbuf[6] == '3' && sbuf[7] == '4' && sbuf[8] == '\0') { - printf("\t success: printf(\"%8.4f\", 0.553415f) == %8.4f\n", 0.553415f); + printf("\t success: printf(\"%%8.4f\", 0.553415f) == %8.4f\n", 0.553415f); } else { - printf("\t FAIL: printf(\"%8.4f\", 0.553415f) != \" 0.5534\", result: %s\n", sbuf); + printf("\t FAIL: printf(\"%%8.4f\", 0.553415f) != \" 0.5534\", result: %s\n", sbuf); ret = -5; } @@ -230,15 +230,24 @@ int test_float(int argc, char *argv[]) ret = -7; } - printf("\t testing printing: printf(0.553415): %8.4f\n", 0.553415); - printf("\t testing pow() with magic value\n"); - printf("\t (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295)));\n"); + printf("\t (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295)));\n"); fflush(stdout); usleep(20000); double powres = (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295))); printf("\t success: result: %8.4f\n", (double)powres); + sprintf(sbuf, "%8.4f", 0.553415); + + if (sbuf[0] == ' ' && sbuf[1] == ' ' && sbuf[2] == '0' && + sbuf[3] == '.' && sbuf[4] == '5' && sbuf[5] == '5' + && sbuf[6] == '3' && sbuf[7] == '4' && sbuf[8] == '\0') { + printf("\t success: printf(\"%%8.4f\", 0.553415) == %8.4f\n", 0.553415); + } else { + printf("\t FAIL: printf(\"%%8.4f\", 0.553415) != \" 0.5534\", result: %s\n", sbuf); + ret = -8; + } + if (ret == 0) { printf("\n SUCCESS: All float and double tests passed.\n"); |