From 00b424f83a281a2cd077e426450c5f18ec55f5a2 Mon Sep 17 00:00:00 2001 From: Andrew Bachmann Date: Wed, 18 May 2005 21:12:16 +0000 Subject: [PATCH] test more values, add sin2+cos2=1 check git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12724 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/libroot/posix/math/math_test.cpp | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/tests/kernel/libroot/posix/math/math_test.cpp b/src/tests/kernel/libroot/posix/math/math_test.cpp index f926a4af42..64ad481d1b 100644 --- a/src/tests/kernel/libroot/posix/math/math_test.cpp +++ b/src/tests/kernel/libroot/posix/math/math_test.cpp @@ -41,12 +41,29 @@ main(int argc, char **argv) status_t result = B_OK; + // test cos2 + sin2 = 1 + fprintf(stdout, "value\tsin2()+cos2()\n"); + for (int i = -63 ; i <= 63 ; i++) { + double f = (double)i/7.0; + double x = sin(f); + double y = cos(f); + if (fabs(x*x + y*y - 1.0) > 0.000001) { + fprintf(stdout, "%0.3f\t%0.10f", f, x*x + y*y); + fprintf(stdout, " **"); + fprintf(stdout, "\n"); + result = B_ERROR; + } + } + fprintf(stdout, "\n"); + // test sin fprintf(stdout, "value\tsin(value)\tbe_sin(value)\n"); - for (int i = -9 ; i <= 9 ; i++) { - double f = (double)i; - fprintf(stdout, "%0.1f\t%0.10f\t%0.10f", f, sin(f), be_sin(f)); - if (sin(f) != be_sin(f)) { + for (int i = -63 ; i <= 63 ; i++) { + double f = (double)i/7.0; + double x = sin(f); + double y = be_sin(f); + fprintf(stdout, "%0.3f\t%0.10f\t%0.10f", f, x, y); + if (fabs(x - y) > 0.000001) { fprintf(stdout, " **"); result = B_ERROR; } @@ -56,10 +73,12 @@ main(int argc, char **argv) fprintf(stdout, "value\tcos(value)\tbe_cos(value)\n"); // test cos - for (int i = -9 ; i <= 9 ; i++) { - double f = (double)i; - fprintf(stdout, "%0.1f\t%0.10f\t%0.10f", f, cos(f), be_cos(f)); - if (cos(f) != be_cos(f)) { + for (int i = -63 ; i <= 63 ; i++) { + double f = (double)i/7.0; + double x = cos(f); + double y = be_cos(f); + fprintf(stdout, "%0.3f\t%0.10f\t%0.10f", f, x, y); + if (fabs(x - y) > 0.000001) { fprintf(stdout, " **"); result = B_ERROR; } @@ -69,10 +88,10 @@ main(int argc, char **argv) fprintf(stdout, "arg1\targ2\tcopysign()\tbe_copysign()\n"); // test copysign - for (int i = -9 ; i <= 9 ; i++) { - for (int j = -9 ; j <= 9 ; j++) { - double f = (double)i; - double g = (double)j; + for (int i = -21 ; i <= 21 ; i++) { + for (int j = -36 ; j <= 36 ; j++) { + double f = (double)i/3.0; + double g = (double)j/4.0; double x = copysign(f, g); double y = be_copysign(f, g); if ((x != y) && !(isnan(x) && isnan(y))) {