From a3344504d04dbededaceb7c46e41d739b289b7f4 Mon Sep 17 00:00:00 2001 From: Andrew Bachmann Date: Wed, 18 May 2005 19:59:38 +0000 Subject: [PATCH] add copysign test, formatting changes git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12719 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/libroot/posix/math/math_test.cpp | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/tests/kernel/libroot/posix/math/math_test.cpp b/src/tests/kernel/libroot/posix/math/math_test.cpp index 1c22112a9f..c6b4d40178 100644 --- a/src/tests/kernel/libroot/posix/math/math_test.cpp +++ b/src/tests/kernel/libroot/posix/math/math_test.cpp @@ -6,12 +6,10 @@ #include #include +#include #include #include -static double (*be_sin)(double); -static double (*be_cos)(double); - static image_id get_libroot_id() { @@ -26,22 +24,59 @@ get_libroot_id() } +static double (*be_sin)(double); +static double (*be_cos)(double); +static double (*be_copysign)(double, double); +static double (*be_drem)(double, double); + + int main(int argc, char **argv) { image_id libroot = get_libroot_id(); assert(get_image_symbol(libroot, "sin", B_SYMBOL_TYPE_TEXT, (void**)&be_sin) == B_OK); assert(get_image_symbol(libroot, "cos", B_SYMBOL_TYPE_TEXT, (void**)&be_cos) == B_OK); + assert(get_image_symbol(libroot, "copysign", B_SYMBOL_TYPE_TEXT, (void**)&be_copysign) == B_OK); + assert(get_image_symbol(libroot, "drem", B_SYMBOL_TYPE_TEXT, (void**)&be_drem) == B_OK); - fprintf(stdout, "value\t\tsin(value)\tbe_sin(value)\tcos(value)\tbe_cos(value)\n"); status_t result = B_OK; - for (int i = -10 ; i < 10 ; i++) { + + // 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.10f\t%0.10f\t%0.10f\t%0.10f\t%0.10f\n", - f, sin(f), be_sin(f), cos(f), be_cos(f)); - if ((sin(f) != be_sin(f)) || (cos(f) != be_cos(f))) { + fprintf(stdout, "%0.1f\t%0.10f\t%0.10f\n", f, sin(f), be_sin(f)); + if (sin(f) != be_sin(f)) { result = B_ERROR; } } + fprintf(stdout, "\n"); + + 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\n", f, cos(f), be_cos(f)); + if (cos(f) != be_cos(f)) { + result = B_ERROR; + } + } + fprintf(stdout, "\n"); + + fprintf(stdout, "arg1\targ2\tcopysign()\tbe_copysign()\n"); + // test copysign + for (int i = -2 ; i <= 2 ; i++) { + for (int j = -2 ; j <= 2 ; j++) { + double f = (double)i; + double g = (double)j; + fprintf(stdout, "%0.1f\t%0.1f\t%0.10f\t%0.10f\n", + f, g, copysign(f, g), be_copysign(f, g)); + if (copysign(f, g) != be_copysign(f, g)) { + result = B_ERROR; + } + } + } + fprintf(stdout, "\n"); + return result; }