From fd95457f053c4d6fd2c469daddcc39721a507ced Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Tue, 20 Oct 2015 21:53:33 -0700 Subject: [PATCH] Implementing the full suite of math.h functions in PAL. --- src/classlibnative/bcltype/arrayhelpers.h | 2 +- src/classlibnative/float/floatnative.cpp | 18 +- src/jit/assertionprop.cpp | 10 +- src/jit/gentree.cpp | 8 +- src/jit/valuenum.cpp | 4 +- src/pal/inc/pal.h | 44 +- src/pal/inc/pal_math.h | 305 +++ src/pal/src/CMakeLists.txt | 2 +- src/pal/src/cruntime/finite.cpp | 410 ---- src/pal/src/cruntime/math.cpp | 1814 +++++++++++++++++ src/pal/src/include/pal/palinternal.h | 391 +++- .../tests/palsuite/c_runtime/CMakeLists.txt | 27 +- .../palsuite/c_runtime/acos/CMakeLists.txt | 1 - .../palsuite/c_runtime/acos/test1/test1.c | 145 +- .../c_runtime/acos/test1/testinfo.dat | 3 - .../{_isnan => acosf}/CMakeLists.txt | 1 - .../{_finite => acosf}/test1/CMakeLists.txt | 6 +- .../palsuite/c_runtime/acosf/test1/test1.c | 113 + .../c_runtime/acosf/test1/testinfo.dat | 14 + .../palsuite/c_runtime/acosh/CMakeLists.txt | 3 + .../c_runtime/acosh/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/acosh/test1/test1.c | 116 ++ .../c_runtime/acosh/test1/testinfo.dat | 13 + .../palsuite/c_runtime/acoshf/CMakeLists.txt | 3 + .../c_runtime/acoshf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/acoshf/test1/test1.c | 132 ++ .../c_runtime/acoshf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/asin/CMakeLists.txt | 1 - .../palsuite/c_runtime/asin/test1/test1.c | 174 +- .../c_runtime/asin/test1/testinfo.dat | 3 - .../palsuite/c_runtime/asinf/CMakeLists.txt | 3 + .../c_runtime/asinf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/asinf/test1/test1.c | 113 + .../c_runtime/asinf/test1/testinfo.dat | 14 + .../palsuite/c_runtime/asinh/CMakeLists.txt | 3 + .../c_runtime/asinh/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/asinh/test1/test1.c | 113 + .../c_runtime/asinh/test1/testinfo.dat | 14 + .../palsuite/c_runtime/asinhf/CMakeLists.txt | 3 + .../c_runtime/asinhf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/asinhf/test1/test1.c | 113 + .../c_runtime/asinhf/test1/testinfo.dat | 14 + .../palsuite/c_runtime/atan/CMakeLists.txt | 1 - .../palsuite/c_runtime/atan/test1/test1.c | 137 +- .../c_runtime/atan/test1/testinfo.dat | 3 - .../palsuite/c_runtime/atan2/CMakeLists.txt | 1 - .../palsuite/c_runtime/atan2/test1/test1.c | 131 +- .../palsuite/c_runtime/atan2f/CMakeLists.txt | 3 + .../c_runtime/atan2f/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/atan2f/test1/test1.c | 132 ++ .../c_runtime/atan2f/test1/testinfo.dat | 14 + .../palsuite/c_runtime/atanf/CMakeLists.txt | 3 + .../c_runtime/atanf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/atanf/test1/test1.c | 111 + .../c_runtime/atanf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/atanh/CMakeLists.txt | 3 + .../c_runtime/atanh/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/atanh/test1/test1.c | 115 ++ .../c_runtime/atanh/test1/testinfo.dat | 13 + .../palsuite/c_runtime/atanhf/CMakeLists.txt | 3 + .../c_runtime/atanhf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/atanhf/test1/test1.c | 115 ++ .../c_runtime/atanhf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/ceil/CMakeLists.txt | 1 - .../palsuite/c_runtime/ceil/test1/test1.c | 147 +- .../palsuite/c_runtime/ceilf/CMakeLists.txt | 3 + .../c_runtime/ceilf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/ceilf/test1/test1.c | 115 ++ .../c_runtime/ceilf/test1/testinfo.dat | 14 + .../palsuite/c_runtime/cos/CMakeLists.txt | 1 - .../palsuite/c_runtime/cos/test1/test1.c | 111 +- .../palsuite/c_runtime/cos/test1/testinfo.dat | 3 - .../palsuite/c_runtime/cosf/CMakeLists.txt | 3 + .../{exp/test2 => cosf/test1}/CMakeLists.txt | 8 +- .../palsuite/c_runtime/cosf/test1/test1.c | 114 ++ .../c_runtime/cosf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/cosh/CMakeLists.txt | 1 - .../palsuite/c_runtime/cosh/test1/test1.c | 124 +- .../c_runtime/cosh/test1/testinfo.dat | 3 - .../palsuite/c_runtime/coshf/CMakeLists.txt | 3 + .../c_runtime/coshf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/coshf/test1/test1.c | 113 + .../c_runtime/coshf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/exp/CMakeLists.txt | 3 - .../palsuite/c_runtime/exp/test1/test1.c | 114 +- .../palsuite/c_runtime/exp/test2/test2.c | 65 - .../palsuite/c_runtime/exp/test3/test3.c | 110 - .../palsuite/c_runtime/expf/CMakeLists.txt | 3 + .../{exp/test3 => expf/test1}/CMakeLists.txt | 8 +- .../palsuite/c_runtime/expf/test1/test1.c | 123 ++ .../{exp/test2 => expf/test1}/testinfo.dat | 8 +- .../palsuite/c_runtime/fabs/CMakeLists.txt | 1 - .../palsuite/c_runtime/fabs/test1/test1.c | 109 +- .../c_runtime/fabs/test1/testinfo.dat | 5 +- .../palsuite/c_runtime/fabsf/CMakeLists.txt | 3 + .../c_runtime/fabsf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/fabsf/test1/test1.c | 113 + .../c_runtime/fabsf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/floor/CMakeLists.txt | 1 - .../palsuite/c_runtime/floor/test1/test1.c | 136 +- .../c_runtime/floor/test1/testinfo.dat | 3 - .../palsuite/c_runtime/floorf/CMakeLists.txt | 3 + .../c_runtime/floorf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/floorf/test1/test1.c | 115 ++ .../c_runtime/floorf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/fmod/CMakeLists.txt | 1 - .../palsuite/c_runtime/fmod/test1/test1.c | 145 +- .../c_runtime/fmod/test1/testinfo.dat | 3 - .../palsuite/c_runtime/fmodf/CMakeLists.txt | 3 + .../c_runtime/fmodf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/fmodf/test1/test1.c | 140 ++ .../c_runtime/fmodf/test1/testinfo.dat | 13 + .../c_runtime/isfinite/CMakeLists.txt | 3 + .../c_runtime/isfinite/test1/CMakeLists.txt | 19 + .../{_finite => isfinite}/test1/test1.c | 54 +- .../c_runtime/isfinite/test1/testinfo.dat | 14 + .../{_finite => isinf}/CMakeLists.txt | 0 .../c_runtime/isinf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/isinf/test1/test1.c | 123 ++ .../{_finite => isinf}/test1/testinfo.dat | 6 +- .../palsuite/c_runtime/isnan/CMakeLists.txt | 3 + .../{_isnan => isnan}/test1/CMakeLists.txt | 0 .../c_runtime/{_isnan => isnan}/test1/test1.c | 56 +- .../{_isnan => isnan}/test1/testinfo.dat | 6 +- .../palsuite/c_runtime/log/CMakeLists.txt | 1 - .../palsuite/c_runtime/log/test1/test1.c | 175 +- .../palsuite/c_runtime/log/test1/testinfo.dat | 3 - .../palsuite/c_runtime/log10/CMakeLists.txt | 1 - .../palsuite/c_runtime/log10/test1/test1.c | 8 +- .../palsuite/c_runtime/logf/CMakeLists.txt | 3 + .../c_runtime/logf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/logf/test1/test1.c | 124 ++ .../{exp/test3 => logf/test1}/testinfo.dat | 11 +- .../palsuite/c_runtime/pow/test2/test2.c | 2 +- .../palsuite/c_runtime/pow/test3/test3.c | 6 +- .../palsuite/c_runtime/sin/CMakeLists.txt | 1 - .../palsuite/c_runtime/sin/test1/test1.c | 125 +- .../palsuite/c_runtime/sin/test1/testinfo.dat | 3 - .../palsuite/c_runtime/sinf/CMakeLists.txt | 3 + .../c_runtime/sinf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/sinf/test1/test1.c | 114 ++ .../c_runtime/sinf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/sinh/CMakeLists.txt | 1 - .../palsuite/c_runtime/sinh/test1/test1.c | 124 +- .../c_runtime/sinh/test1/testinfo.dat | 3 - .../palsuite/c_runtime/sinhf/CMakeLists.txt | 3 + .../c_runtime/sinhf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/sinhf/test1/test1.c | 113 + .../c_runtime/sinhf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/tan/CMakeLists.txt | 1 - .../palsuite/c_runtime/tan/test1/test1.c | 128 +- .../palsuite/c_runtime/tan/test1/testinfo.dat | 3 - .../palsuite/c_runtime/tanf/CMakeLists.txt | 3 + .../c_runtime/tanf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/tanf/test1/test1.c | 120 ++ .../c_runtime/tanf/test1/testinfo.dat | 13 + .../palsuite/c_runtime/tanh/CMakeLists.txt | 1 - .../palsuite/c_runtime/tanh/test1/test1.c | 124 +- .../c_runtime/tanh/test1/testinfo.dat | 3 - .../palsuite/c_runtime/tanhf/CMakeLists.txt | 3 + .../c_runtime/tanhf/test1/CMakeLists.txt | 19 + .../palsuite/c_runtime/tanhf/test1/test1.c | 113 + .../c_runtime/tanhf/test1/testinfo.dat | 13 + src/pal/tests/palsuite/paltestlist.txt | 29 +- src/pal/tests/palsuite/palverify.dat | 22 +- src/vm/jithelpers.cpp | 12 +- 166 files changed, 7317 insertions(+), 1806 deletions(-) create mode 100644 src/pal/inc/pal_math.h delete mode 100644 src/pal/src/cruntime/finite.cpp create mode 100644 src/pal/src/cruntime/math.cpp rename src/pal/tests/palsuite/c_runtime/{_isnan => acosf}/CMakeLists.txt (98%) rename src/pal/tests/palsuite/c_runtime/{_finite => acosf}/test1/CMakeLists.txt (53%) create mode 100644 src/pal/tests/palsuite/c_runtime/acosf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/acosf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/acosh/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/acosh/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/acosh/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/acosh/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/acoshf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/acoshf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/acoshf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/acoshf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/asinf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/asinf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/asinf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/asinf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/asinh/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/asinh/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/asinh/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/asinh/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/asinhf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/asinhf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/asinhf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/asinhf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/atan2f/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atan2f/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atan2f/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atan2f/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/atanf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atanf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atanf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atanf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/atanh/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atanh/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atanh/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atanh/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/atanhf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atanhf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/atanhf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/atanhf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/ceilf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/ceilf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/ceilf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/ceilf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/cosf/CMakeLists.txt rename src/pal/tests/palsuite/c_runtime/{exp/test2 => cosf/test1}/CMakeLists.txt (50%) create mode 100644 src/pal/tests/palsuite/c_runtime/cosf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/cosf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/coshf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/coshf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/coshf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/coshf/test1/testinfo.dat delete mode 100644 src/pal/tests/palsuite/c_runtime/exp/test2/test2.c delete mode 100644 src/pal/tests/palsuite/c_runtime/exp/test3/test3.c create mode 100644 src/pal/tests/palsuite/c_runtime/expf/CMakeLists.txt rename src/pal/tests/palsuite/c_runtime/{exp/test3 => expf/test1}/CMakeLists.txt (50%) create mode 100644 src/pal/tests/palsuite/c_runtime/expf/test1/test1.c rename src/pal/tests/palsuite/c_runtime/{exp/test2 => expf/test1}/testinfo.dat (51%) create mode 100644 src/pal/tests/palsuite/c_runtime/fabsf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/fabsf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fabsf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/floorf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/floorf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/floorf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/floorf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/fmodf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/fmodf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/fmodf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/isfinite/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/isfinite/test1/CMakeLists.txt rename src/pal/tests/palsuite/c_runtime/{_finite => isfinite}/test1/test1.c (68%) create mode 100644 src/pal/tests/palsuite/c_runtime/isfinite/test1/testinfo.dat rename src/pal/tests/palsuite/c_runtime/{_finite => isinf}/CMakeLists.txt (100%) create mode 100644 src/pal/tests/palsuite/c_runtime/isinf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/isinf/test1/test1.c rename src/pal/tests/palsuite/c_runtime/{_finite => isinf}/test1/testinfo.dat (65%) create mode 100644 src/pal/tests/palsuite/c_runtime/isnan/CMakeLists.txt rename src/pal/tests/palsuite/c_runtime/{_isnan => isnan}/test1/CMakeLists.txt (100%) rename src/pal/tests/palsuite/c_runtime/{_isnan => isnan}/test1/test1.c (59%) rename src/pal/tests/palsuite/c_runtime/{_isnan => isnan}/test1/testinfo.dat (75%) create mode 100644 src/pal/tests/palsuite/c_runtime/logf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/logf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/logf/test1/test1.c rename src/pal/tests/palsuite/c_runtime/{exp/test3 => logf/test1}/testinfo.dat (67%) create mode 100644 src/pal/tests/palsuite/c_runtime/sinf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sinf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sinf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/sinf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/sinhf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sinhf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/sinhf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/sinhf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/tanf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/tanf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/tanf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/tanf/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/tanhf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/tanhf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/tanhf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/tanhf/test1/testinfo.dat diff --git a/src/classlibnative/bcltype/arrayhelpers.h b/src/classlibnative/bcltype/arrayhelpers.h index 9329f1a2f50b..11da24f2d006 100644 --- a/src/classlibnative/bcltype/arrayhelpers.h +++ b/src/classlibnative/bcltype/arrayhelpers.h @@ -110,7 +110,7 @@ class ArrayHelpers template static unsigned int NaNPrepass(REAL keys[], REAL items[], unsigned int left, unsigned int right) { for (unsigned int i = left; i <= right; i++) { - if (_isnan(keys[i])) { + if (isnan(keys[i])) { REAL temp = keys[left]; keys[left] = keys[i]; keys[i] = temp; diff --git a/src/classlibnative/float/floatnative.cpp b/src/classlibnative/float/floatnative.cpp index db3df4422e14..052f59d1dd97 100644 --- a/src/classlibnative/float/floatnative.cpp +++ b/src/classlibnative/float/floatnative.cpp @@ -267,10 +267,10 @@ FCIMPL2_VV(double, COMDouble::PowHelper, double x, double y) double r1; // TODO: we can get rid following code if VC fixes pow function someday. - if(_isnan(y)) { + if(isnan(y)) { return y; // IEEE 754-2008: NaN payload must be preserved } - if(_isnan(x)) { + if(isnan(x)) { return x; // IEEE 754-2008: NaN payload must be preserved } if(IS_DBL_INFINITY(y)) { @@ -348,7 +348,7 @@ void assertDoublesWithinRange(double r1, double r2) { WRAPPER_NO_CONTRACT; - if (_finite(r1) && _finite(r2)) + if (isfinite(r1) && isfinite(r2)) { // Both numbers are finite--we need to check that they are close to // each other. If they are large (> 1), the error could also be large, @@ -359,7 +359,7 @@ void assertDoublesWithinRange(double r1, double r2) assert((error < (EPSILON * norm)) || (error < EPSILON)); } - else if (!_isnan(r1) && !_isnan(r2)) + else if (!isnan(r1) && !isnan(r2)) { // At least one of r1 and r2 is infinite, so when multiplied by // (1 + EPSILON) they should be the same infinity. @@ -381,10 +381,10 @@ FCIMPL2_VV(double, COMDouble::Pow, double x, double y) double r1, r2; - if(_isnan(y)) { + if(isnan(y)) { return y; // IEEE 754-2008: NaN payload must be preserved } - if(_isnan(x)) { + if(isnan(x)) { return x; // IEEE 754-2008: NaN payload must be preserved } @@ -423,10 +423,10 @@ FCIMPL2_VV(double, COMDouble::Pow, double x, double y) double r1; - if(_isnan(y)) { + if(isnan(y)) { return y; // IEEE 754-2008: NaN payload must be preserved } - if(_isnan(x)) { + if(isnan(x)) { return x; // IEEE 754-2008: NaN payload must be preserved } @@ -483,7 +483,7 @@ FCIMPL1_V(double, COMDouble::Round, double d) flrTempVal -= 1.0; } } - flrTempVal = _copysign(flrTempVal, d); + flrTempVal = copysign(flrTempVal, d); return flrTempVal; FCIMPLEND #endif // defined(_TARGET_X86_) diff --git a/src/jit/assertionprop.cpp b/src/jit/assertionprop.cpp index fccec9808974..cf75104d3816 100644 --- a/src/jit/assertionprop.cpp +++ b/src/jit/assertionprop.cpp @@ -982,7 +982,7 @@ unsigned Compiler::optCreateAssertion(GenTreePtr op1, GenTreePtr op2, { noway_assert(op2->gtOper == GT_CNS_DBL); /* If we have an NaN value then don't record it */ - if (_isnan(op2->gtDblCon.gtDconVal)) + if (isnan(op2->gtDblCon.gtDconVal)) { goto DONE_ASSERTION; // Don't make an assertion } @@ -1322,8 +1322,8 @@ bool Compiler::optAssertionVnInvolvesNan(AssertionDsc* assertion) if (vnStore->IsVNConstant(vns[i])) { var_types type = vnStore->TypeOfVN(vns[i]); - if ((type == TYP_FLOAT && _isnan(vnStore->ConstantValue(vns[i])) != 0) || - (type == TYP_DOUBLE && _isnan(vnStore->ConstantValue(vns[i])) != 0)) + if ((type == TYP_FLOAT && isnan(vnStore->ConstantValue(vns[i])) != 0) || + (type == TYP_DOUBLE && isnan(vnStore->ConstantValue(vns[i])) != 0)) { return true; } @@ -2769,7 +2769,7 @@ GenTreePtr Compiler::optAssertionPropGlobal_RelOp(EXPSET_TP assertions, const Ge // which will yield a false correctly. Instead if IL had "op1 != NaN", then we already // made op1 NaN which will yield a true correctly. Note that this is irrespective of the // assertion we have made. - allowReverse = (_isnan(constant) == 0); + allowReverse = (isnan(constant) == 0); } else if (op1->TypeGet() == TYP_FLOAT) { @@ -2777,7 +2777,7 @@ GenTreePtr Compiler::optAssertionPropGlobal_RelOp(EXPSET_TP assertions, const Ge op1->ChangeOperConst(GT_CNS_DBL); op1->gtDblCon.gtDconVal = constant; // See comments for TYP_DOUBLE. - allowReverse = (_isnan(constant) == 0); + allowReverse = (isnan(constant) == 0); } else if (op1->TypeGet() == TYP_REF) { diff --git a/src/jit/gentree.cpp b/src/jit/gentree.cpp index d6bd3af7777d..99a343d4f760 100644 --- a/src/jit/gentree.cpp +++ b/src/jit/gentree.cpp @@ -9602,8 +9602,8 @@ GenTreePtr Compiler::gtFoldExprConst(GenTreePtr tree) assert (genActualType(tree->CastToType()) == tree->gtType); - if ((op1->gtType == TYP_FLOAT && !_finite(forceCastToFloat(d1))) || - (op1->gtType == TYP_DOUBLE && !_finite(d1))) + if ((op1->gtType == TYP_FLOAT && !isfinite(forceCastToFloat(d1))) || + (op1->gtType == TYP_DOUBLE && !isfinite(d1))) { // The floating point constant is not finite. The ECMA spec says, in // III 3.27, that "...if overflow occurs converting a floating point type @@ -9643,7 +9643,7 @@ GenTreePtr Compiler::gtFoldExprConst(GenTreePtr tree) case TYP_FLOAT: case TYP_DOUBLE: if (op1->gtType == TYP_FLOAT) - d1 = forceCastToFloat(d1); // it's only !_finite() after this conversion + d1 = forceCastToFloat(d1); // it's only !isfinite() after this conversion goto CNS_DOUBLE; default: unreached(); @@ -10385,7 +10385,7 @@ GenTreePtr Compiler::gtFoldExprConst(GenTreePtr tree) * For unordered operations (i.e. the GTF_RELOP_NAN_UN flag is set) * the result is always true - return 1. */ - if (_isnan(d1) || _isnan(d2)) + if (isnan(d1) || isnan(d2)) { #ifdef DEBUG if (verbose) diff --git a/src/jit/valuenum.cpp b/src/jit/valuenum.cpp index 9476e5472ff1..0684c7e60ee2 100644 --- a/src/jit/valuenum.cpp +++ b/src/jit/valuenum.cpp @@ -956,8 +956,8 @@ ValueNum ValueNumStore::VNForFunc(var_types typ, VNFunc func, ValueNum arg0VN, V // comparison would return false, an unordered comparison // will return true if any operands are a NaN. We only perform // ordered NaN comparison in EvalComparison. - if ((arg0IsFloating && _isnan(GetConstantDouble(arg0VN))) || - (arg1IsFloating && _isnan(GetConstantDouble(arg1VN)))) + if ((arg0IsFloating && isnan(GetConstantDouble(arg0VN))) || + (arg1IsFloating && isnan(GetConstantDouble(arg1VN)))) { canFold = false; } diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index 6cc997885776..387c4221b9b1 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -6003,14 +6003,6 @@ CoCreateGuid(OUT GUID * pguid); #define ungetc PAL_ungetc #define setvbuf PAL_setvbuf #define atol PAL_atol -#define acos PAL_acos -#define asin PAL_asin -#define atan2 PAL_atan2 -#define exp PAL_exp -#define labs PAL_labs -#define log PAL_log -#define log10 PAL_log10 -#define pow PAL_pow #define malloc PAL_malloc #define free PAL_free #define mkstemp PAL_mkstemp @@ -6023,6 +6015,9 @@ CoCreateGuid(OUT GUID * pguid); #define _wcstoui64 PAL__wcstoui64 #define _flushall PAL__flushall +// See for the method definitions +// #include is below with the forward declarations + #ifdef _AMD64_ #define _mm_getcsr PAL__mm_getcsr #define _mm_setcsr PAL__mm_setcsr @@ -6207,40 +6202,11 @@ unsigned int __cdecl _rotr(unsigned int value, int shift) } PALIMPORT int __cdecl abs(int); -PALIMPORT double __cdecl fabs(double); -#ifndef PAL_STDCPP_COMPAT -PALIMPORT LONG __cdecl labs(LONG); -PALIMPORT double __cdecl fabs(double); -#endif // !PAL_STDCPP_COMPAT +PALIMPORT long __cdecl labs(long); // clang complains if this is declared with __int64 PALIMPORT long long __cdecl llabs(long long); -PALIMPORT double __cdecl sqrt(double); -PALIMPORT double __cdecl log(double); -PALIMPORT double __cdecl log10(double); -PALIMPORT double __cdecl exp(double); -PALIMPORT double __cdecl pow(double, double); -PALIMPORT double __cdecl acos(double); -PALIMPORT double __cdecl asin(double); -PALIMPORT double __cdecl atan(double); -PALIMPORT double __cdecl atan2(double,double); -PALIMPORT double __cdecl cos(double); -PALIMPORT double __cdecl sin(double); -PALIMPORT double __cdecl tan(double); -PALIMPORT double __cdecl cosh(double); -PALIMPORT double __cdecl sinh(double); -PALIMPORT double __cdecl tanh(double); -PALIMPORT double __cdecl fmod(double, double); -PALIMPORT float __cdecl fmodf(float, float); -PALIMPORT double __cdecl floor(double); -PALIMPORT double __cdecl ceil(double); -PALIMPORT float __cdecl fabsf(float); -PALIMPORT double __cdecl modf(double, double *); -PALIMPORT float __cdecl modff(float, float *); - -PALIMPORT int __cdecl _finite(double); -PALIMPORT int __cdecl _isnan(double); -PALIMPORT double __cdecl _copysign(double, double); +#include #ifndef PAL_STDCPP_COMPAT diff --git a/src/pal/inc/pal_math.h b/src/pal/inc/pal_math.h new file mode 100644 index 000000000000..6c45183c504e --- /dev/null +++ b/src/pal/inc/pal_math.h @@ -0,0 +1,305 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*++ + +Module Name: + + pal_math.h + +Abstract: + + Defines all the math.h functions for the Platform Abstraction Layer. + +--*/ + +#ifndef __PAL_MATH_H__ +#define __PAL_MATH_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Some C runtime functions needs to be reimplemented by the PAL. + To avoid name collisions, those functions have been renamed using + defines */ +#ifdef PLATFORM_UNIX +#ifndef PAL_STDCPP_COMPAT + +// 7.12.0 General Macros +#define INFINITY (1.0f / 0.0f) +#define NAN (0.0f / 0.0f) + +// 7.12.3 Classification Macros +#define isfinite(x) ((x - x) == 0) +#define isinf(x) ((x == x) && ((x - x) != 0)) +#define isnan(x) (x != x) + +// 7.12.4 Trigonometric Functions +#define acos PAL_acos +#define acosf PAL_acosf + +#define asin PAL_asin +#define asinf PAL_asinf + +#define atan PAL_atan +#define atanf PAL_atanf + +#define atan2 PAL_atan2 +#define atan2f PAL_atan2f + +#define cos PAL_cos +#define cosf PAL_cosf + +#define sin PAL_sin +#define sinf PAL_sinf + +#define tan PAL_tan +#define tanf PAL_tanf + +// 7.12.5 Hyperbolic Functions +#define acosh PAL_acosh +#define acoshf PAL_acoshf + +#define asinh PAL_asinh +#define asinhf PAL_asinhf + +#define atanh PAL_atanh +#define atanhf PAL_atanhf + +#define cosh PAL_cosh +#define coshf PAL_coshf + +#define sinh PAL_sinh +#define sinhf PAL_sinhf + +#define tanh PAL_tanh +#define tanhf PAL_tanhf + +// 7.12.6 Exponential and Logarithmic Functions +#define exp PAL_exp +#define expf PAL_expf + +#define exp2 PAL_exp2 +#define exp2f PAL_exp2f + +#define expm1 PAL_expm1 +#define expm1f PAL_expm1f + +#define frexp PAL_frexp +#define frexpf PAL_frexpf + +#define ldexp PAL_ldexp +#define ldexpf PAL_ldexpf + +#define log PAL_log +#define logf PAL_logf + +#define log10 PAL_log10 +#define log10f PAL_log10f + +#define log1p PAL_log1p +#define log1pf PAL_log1pf + +#define log2 PAL_log2 +#define log2f PAL_log2f + +#define modf PAL_modf +#define modff PAL_modff + +#define scalbn PAL_scalbn +#define scalbnf PAL_scalbnf + +// 7.12.7 Power and Absolute-Value Functions +#define cbrt PAL_cbrt +#define cbrtf PAL_cbrtf + +#define fabs PAL_fabs +#define fabsf PAL_fabsf + +#define hypot PAL_hypot +#define hypotf PAL_hypotf + +#define pow PAL_pow +#define powf PAL_powf + +#define sqrt PAL_sqrt +#define sqrtf PAL_sqrtf + +// 7.12.8 Error and Gamma Functions +#define erf PAL_erf +#define erff PAL_erff + +#define erfc PAL_erfc +#define erfcf PAL_erfcf + +#define lgamma PAL_lgamma +#define lgammaf PAL_lgammaf + +#define tgamma PAL_tgamma +#define tgammaf PAL_tgammaf + +// 7.12.9 Nearest Integer Functions +#define ceil PAL_ceil +#define ceilf PAL_ceilf + +#define floor PAL_floor +#define floorf PAL_floorf + +// 7.12.10 Remainder Functions +#define fmod PAL_fmod +#define fmodf PAL_fmodf + +#define remquo PAL_remquo +#define remquof PAL_remquof + +// 7.12.11 Manipulation Functions +#define copysign PAL_copysign +#define copysignf PAL_copysignf + +#define nextafter PAL_nextafter +#define nextafterf PAL_nextafterf + +// 7.12.13 Floating Multiply-Add Function +#define fma PAL_fma +#define fmaf PAL_fmaf + +#endif // !PAL_STDCPP_COMPAT +#endif // PLATFORM_UNIX + +// 7.12.4 Trigonometric Functions +PALIMPORT double __cdecl acos(double); +PALIMPORT float __cdecl acosf(float); + +PALIMPORT double __cdecl asin(double); +PALIMPORT float __cdecl asinf(float); + +PALIMPORT double __cdecl atan(double); +PALIMPORT float __cdecl atanf(float); + +PALIMPORT double __cdecl atan2(double, double); +PALIMPORT float __cdecl atan2f(float, float); + +PALIMPORT double __cdecl cos(double); +PALIMPORT float __cdecl cosf(float); + +PALIMPORT double __cdecl sin(double); +PALIMPORT float __cdecl sinf(float); + +PALIMPORT double __cdecl tan(double); +PALIMPORT float __cdecl tanf(float); + +// 7.12.5 Hyperbolic Functions +PALIMPORT double __cdecl acosh(double); +PALIMPORT float __cdecl acoshf(float); + +PALIMPORT double __cdecl asinh(double); +PALIMPORT float __cdecl asinhf(float); + +PALIMPORT double __cdecl atanh(double); +PALIMPORT float __cdecl atanhf(float); + +PALIMPORT double __cdecl cosh(double); +PALIMPORT float __cdecl coshf(float); + +PALIMPORT double __cdecl sinh(double); +PALIMPORT float __cdecl sinhf(float); + +PALIMPORT double __cdecl tanh(double); +PALIMPORT float __cdecl tanhf(float); + +// 7.12.6 Exponential and Logarithmic Functions +PALIMPORT double __cdecl exp(double); +PALIMPORT float __cdecl expf(float); + +PALIMPORT double __cdecl exp2(double); +PALIMPORT float __cdecl exp2f(float); + +PALIMPORT double __cdecl expm1(double); +PALIMPORT float __cdecl expm1f(float); + +PALIMPORT double __cdecl frexp(double, int*); +PALIMPORT float __cdecl frexpf(float, int*); + +PALIMPORT double __cdecl ldexp(double, int); +PALIMPORT float __cdecl ldexpf(float, int); + +PALIMPORT double __cdecl log(double); +PALIMPORT float __cdecl logf(float); + +PALIMPORT double __cdecl log10(double); +PALIMPORT float __cdecl log10f(float); + +PALIMPORT double __cdecl log1p(double); +PALIMPORT float __cdecl log1pf(float); + +PALIMPORT double __cdecl log2(double); +PALIMPORT float __cdecl log2f(float); + +PALIMPORT double __cdecl modf(double, double*); +PALIMPORT float __cdecl modff(float, float*); + +PALIMPORT double __cdecl scalbn(double, int); +PALIMPORT float __cdecl scalbnf(float, int); + +// 7.12.7 Power and Absolute-Value Functions +PALIMPORT double __cdecl cbrt(double); +PALIMPORT float __cdecl cbrtf(float); + +PALIMPORT double __cdecl fabs(double); +PALIMPORT float __cdecl fabsf(float); + +PALIMPORT double __cdecl hypot(double, double); +PALIMPORT float __cdecl hypotf(float, float); + +PALIMPORT double __cdecl pow(double, double); +PALIMPORT float __cdecl powf(float, float); + +PALIMPORT double __cdecl sqrt(double); +PALIMPORT float __cdecl sqrtf(float); + +// 7.12.8 Error and Gamma Functions +PALIMPORT double __cdecl erf(double); +PALIMPORT float __cdecl erff(float); + +PALIMPORT double __cdecl erfc(double); +PALIMPORT float __cdecl erfcf(float); + +PALIMPORT double __cdecl lgamma(double); +PALIMPORT float __cdecl lgammaf(float); + +PALIMPORT double __cdecl tgamma(double); +PALIMPORT float __cdecl tgammaf(float); + +// 7.12.9 Nearest Integer Functions +PALIMPORT double __cdecl ceil(double); +PALIMPORT float __cdecl ceilf(float); + +PALIMPORT double __cdecl floor(double); +PALIMPORT float __cdecl floorf(float); + +// 7.12.10 Remainder Functions +PALIMPORT double __cdecl fmod(double, double); +PALIMPORT float __cdecl fmodf(float, float); + +PALIMPORT double __cdecl remquo(double, double, int*); +PALIMPORT float __cdecl remquof(float, float, int*); + +// 7.12.11 Manipulation Functions +PALIMPORT double __cdecl copysign(double, double); +PALIMPORT float __cdecl copysignf(float, float); + +PALIMPORT double __cdecl nextafter(double, double); +PALIMPORT float __cdecl nextafterf(float, float); + +// 7.12.13 Floating Multiply-Add Function +PALIMPORT double __cdecl fma(double, double, double); +PALIMPORT float __cdecl fmaf(float, float, float); + +#ifdef __cplusplus +} +#endif + +#endif //__PAL_MATH_H__ diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt index 03b3ea694b28..9074ce8ca2d6 100644 --- a/src/pal/src/CMakeLists.txt +++ b/src/pal/src/CMakeLists.txt @@ -90,9 +90,9 @@ endif() set(SOURCES cruntime/file.cpp cruntime/filecrt.cpp - cruntime/finite.cpp cruntime/lstr.cpp cruntime/malloc.cpp + cruntime/math.cpp cruntime/mbstring.cpp cruntime/misc.cpp cruntime/misctls.cpp diff --git a/src/pal/src/cruntime/finite.cpp b/src/pal/src/cruntime/finite.cpp deleted file mode 100644 index 115a20becb9d..000000000000 --- a/src/pal/src/cruntime/finite.cpp +++ /dev/null @@ -1,410 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*++ - - - -Module Name: - - finite.cpp - -Abstract: - - Implementation of _finite function (Windows specific runtime function). - - - ---*/ - -#include "pal/palinternal.h" -#include "pal/dbgmsg.h" -#include - -#if HAVE_IEEEFP_H -#include -#endif // HAVE_IEEEFP_H -#include - -#define PAL_NAN sqrt(-1) -#define PAL_POSINF -log(0) -#define PAL_NEGINF log(0) - -SET_DEFAULT_DEBUG_CHANNEL(CRT); - - -/*++ -Function: - _finite - -Determines whether given double-precision floating point value is finite. - -Return Value - -_finite returns a nonzero value (TRUE) if its argument x is not -infinite, that is, if -INF < x < +INF. It returns 0 (FALSE) if the -argument is infinite or a NaN. - -Parameter - -x Double-precision floating-point value - ---*/ -int -__cdecl -_finite( - double x) -{ - int ret; - PERF_ENTRY(_finite); - ENTRY("_finite (x=%f)\n", x); -#if defined(_IA64_) && defined (_HPUX_) - ret = !isnan(x) && x != PAL_POSINF && x != PAL_NEGINF; -#else - ret = isfinite(x); -#endif - LOGEXIT("_finite returns int %d\n", ret); - PERF_EXIT(_finite); - return ret; -} - - -/*++ -Function: - _isnan - -See MSDN doc ---*/ -int -__cdecl -_isnan( - double x) -{ - int ret; - - PERF_ENTRY(_isnan); - ENTRY("_isnan (x=%f)\n", x); - ret = isnan(x); - LOGEXIT("_isnan returns int %d\n", ret); - PERF_EXIT(_isnan); - return ret; -} - -/*++ -Function: - _copysign - -See MSDN doc ---*/ -double -__cdecl -_copysign( - double x, - double y) -{ - double ret; - - PERF_ENTRY(_copysign); - ENTRY("_copysign (x=%f,y=%f)\n", x, y); - ret = copysign(x, y); - LOGEXIT("_copysign returns double %f\n", ret); - PERF_EXIT(_copysign); - return ret; -} - -/*++ -Function: - acos - -See MSDN. ---*/ -PALIMPORT double __cdecl PAL_acos(double x) -{ - double ret; - - PERF_ENTRY(acos); - ENTRY("acos (x=%f)\n", x); -#if !HAVE_COMPATIBLE_ACOS - errno = 0; -#endif // HAVE_COMPATIBLE_ACOS - ret = acos(x); -#if !HAVE_COMPATIBLE_ACOS - if (errno == EDOM) - { - ret = PAL_NAN; // NaN - } -#endif // HAVE_COMPATIBLE_ACOS - LOGEXIT("acos returns double %f\n", ret); - PERF_EXIT(acos); - return ret; -} - -/*++ -Function: - asin - -See MSDN. ---*/ -PALIMPORT double __cdecl PAL_asin(double x) -{ - double ret; - - PERF_ENTRY(asin); - ENTRY("asin (x=%f)\n", x); -#if !HAVE_COMPATIBLE_ASIN - errno = 0; -#endif // HAVE_COMPATIBLE_ASIN - ret = asin(x); -#if !HAVE_COMPATIBLE_ASIN - if (errno == EDOM) - { - ret = PAL_NAN; // NaN - } -#endif // HAVE_COMPATIBLE_ASIN - LOGEXIT("asin returns double %f\n", ret); - PERF_EXIT(asin); - return ret; -} - -/*++ -Function: - atan2 - -See MSDN. ---*/ -PALIMPORT double __cdecl PAL_atan2(double y, double x) -{ - double ret; - - PERF_ENTRY(atan2); - ENTRY("atan2 (y=%f, x=%f)\n", y, x); -#if !HAVE_COMPATIBLE_ATAN2 - errno = 0; -#endif // !HAVE_COMPATIBLE_ATAN2 - ret = atan2(y, x); -#if !HAVE_COMPATIBLE_ATAN2 - if (errno == EDOM) - { -#if HAVE_COPYSIGN - if (x == 0.0 && y == 0.0) - { - const double sign_x = copysign (1.0, x); - const double sign_y = copysign (1.0, y); - if (sign_x > 0) - { - ret = copysign (0.0, sign_y); - } - else - { - ret = copysign (atan2 (0.0, -1.0), sign_y); - } - } -#else // HAVE_COPYSIGN -#error Missing copysign or equivalent on this platform! -#endif // HAVE_COPYSIGN - } -#endif // !HAVE_COMPATIBLE_ATAN2 - LOGEXIT("atan2 returns double %f\n", ret); - PERF_EXIT(atan2); - return ret; -} - -/*++ -Function: - exp - -See MSDN. ---*/ -PALIMPORT double __cdecl PAL_exp(double x) -{ - double ret; - - PERF_ENTRY(exp); - ENTRY("exp (x=%f)\n", x); -#if !HAVE_COMPATIBLE_EXP - if (x == 1.0) - { - ret = M_E; - } - else - { - ret = exp(x); - } -#else // !HAVE_COMPATIBLE_EXP - ret = exp(x); -#endif // !HAVE_COMPATIBLE_EXP - LOGEXIT("exp returns double %f\n", ret); - PERF_EXIT(exp); - return ret; -} - -/*++ -Function: - labs - -See MSDN. ---*/ -PALIMPORT LONG __cdecl PAL_labs(LONG l) -{ - long lRet; - - PERF_ENTRY(labs); - ENTRY("labs (l=%ld)\n", l); - - lRet = labs(l); - - LOGEXIT("labs returns long %ld\n", lRet); - PERF_EXIT(labs); - /* This explicit cast to LONG is used to silence any potential warnings - due to implicitly casting the native long lRet to LONG when returning. */ - return (LONG)lRet; -} - -/*++ -Function: - log - -See MSDN. ---*/ -PALIMPORT double __cdecl PAL_log(double x) -{ - double ret; - - PERF_ENTRY(log); - ENTRY("log (x=%f)\n", x); -#if !HAVE_COMPATIBLE_LOG - errno = 0; -#endif // !HAVE_COMPATIBLE_LOG - ret = log(x); -#if !HAVE_COMPATIBLE_LOG - if (errno == EDOM) - { - if (x < 0) - { - ret = PAL_NAN; // NaN - } - } -#endif // !HAVE_COMPATIBLE_LOG - LOGEXIT("log returns double %f\n", ret); - PERF_EXIT(log); - return ret; -} - -/*++ -Function: - log10 - -See MSDN. ---*/ -PALIMPORT double __cdecl PAL_log10(double x) -{ - double ret; - - PERF_ENTRY(log10); - ENTRY("log10 (x=%f)\n", x); -#if !HAVE_COMPATIBLE_LOG10 - errno = 0; -#endif // !HAVE_COMPATIBLE_LOG10 - ret = log10(x); -#if !HAVE_COMPATIBLE_LOG10 - if (errno == EDOM) - { - if (x < 0) - { - ret = PAL_NAN; // NaN - } - } -#endif // !HAVE_COMPATIBLE_LOG10 - LOGEXIT("log10 returns double %f\n", ret); - PERF_EXIT(log10); - return ret; -} - -/*++ -Function: - pow - -See MSDN. ---*/ -PALIMPORT double __cdecl PAL_pow(double x, double y) -{ - double ret; - - PERF_ENTRY(pow); - ENTRY("pow (x=%f, y=%f)\n", x, y); -#if !HAVE_COMPATIBLE_POW - if (y == PAL_POSINF && !isnan(x)) // +Inf - { - if (x == 1.0 || x == -1.0) - { - ret = PAL_NAN; // NaN - } - else if (x > -1.0 && x < 1.0) - { - ret = 0.0; - } - else - { - ret = PAL_POSINF; // +Inf - } - } - else if (y == PAL_NEGINF && !isnan(x)) // -Inf - { - if (x == 1.0 || x == -1.0) - { - ret = PAL_NAN; // NaN - } - else if (x > -1.0 && x < 1.0) - { - ret = PAL_POSINF; // +Inf - } - else - { - ret = 0.0; - } - } - else if (x == 0.0 && y < 0.0) - { - ret = PAL_POSINF; // +Inf - } - else -#endif // !HAVE_COMPATIBLE_POW - if (y == 0.0 && isnan(x)) - { - // Windows returns NaN for pow(NaN, 0), but POSIX specifies - // a return value of 1 for that case. We need to return - // the same result as Windows. - ret = PAL_NAN; - } - else - { - ret = pow(x, y); - } -#if !HAVE_VALID_NEGATIVE_INF_POW - if (ret == PAL_POSINF && x < 0 && finite(x) && ceil(y/2) != floor(y/2)) - { - ret = PAL_NEGINF; // -Inf - } -#endif // !HAVE_VALID_NEGATIVE_INF_POW -#if !HAVE_VALID_POSITIVE_INF_POW - /* - * The even/odd test in the if (this one and the one above) used to be ((long long) y % 2 == 0) - * on SPARC (long long) y for large y (>2**63) is always 0x7fffffff7fffffff, which - * is an odd number, so the test ((long long) y % 2 == 0) will always fail for - * large y. Since large double numbers are always even (e.g., the representation of - * 1E20+1 is the same as that of 1E20, the last .+1. is too insignificant to be part - * of the representation), this test will always return the wrong result for large y. - * - * The (ceil(y/2) == floor(y/2)) test is slower, but more robust. - */ - if (ret == PAL_NEGINF && x < 0 && finite(x) && ceil(y/2) == floor(y/2)) - { - ret = PAL_POSINF; // +Inf - } -#endif // !HAVE_VALID_POSITIVE_INF_POW - LOGEXIT("pow returns double %f\n", ret); - PERF_EXIT(pow); - return ret; -} diff --git a/src/pal/src/cruntime/math.cpp b/src/pal/src/cruntime/math.cpp new file mode 100644 index 000000000000..08b6229a1d72 --- /dev/null +++ b/src/pal/src/cruntime/math.cpp @@ -0,0 +1,1814 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*++ + +Module Name: + + math.cpp + +Abstract: + + Implements all the math.h functions for the Platform Abstraction Layer. + +--*/ + +#include "pal/palinternal.h" +#include "pal/dbgmsg.h" + +#include + +#if HAVE_IEEEFP_H +#include +#endif // HAVE_IEEEFP_H + +#include + +SET_DEFAULT_DEBUG_CHANNEL(CRT); + +// 7.12.4 Trigonometric Functions +/*++ +Function: + acos + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_acos(double x) +{ + double ret; + PERF_ENTRY(acos); + ENTRY("Entry to acos: double x=%f\n", x); + +#if !(HAVE_COMPATIBLE_ACOS) + errno = 0; +#endif // !(HAVE_COMPATIBLE_ACOS) + + ret = acos(x); + +#if !HAVE_COMPATIBLE_ACOS + if (errno == EDOM) + { + ret = NAN; + } +#endif // !(HAVE_COMPATIBLE_ACOS) + + LOGEXIT("Exit from acos: double return=%f\n", ret); + PERF_EXIT(acos); + return ret; +} + +/*++ +Function: + acosf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_acosf(float x) +{ + float ret; + PERF_ENTRY(acosf); + ENTRY("Entry to acosf: float x=%f\n", x); + +#if !(HAVE_COMPATIBLE_ACOS) + errno = 0; +#endif // !(HAVE_COMPATIBLE_ACOS) + + ret = acosf(x); + +#if !HAVE_COMPATIBLE_ACOS + if (errno == EDOM) + { + ret = NAN; + } +#endif // !(HAVE_COMPATIBLE_ACOS) + + LOGEXIT("Exit from acosf: float return=%f\n", ret); + PERF_EXIT(acosf); + return ret; +} + +/*++ +Function: + asin + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_asin(double x) +{ + double ret; + PERF_ENTRY(asin); + ENTRY("Entry to asin: double x=%f\n", x); + +#if !(HAVE_COMPATIBLE_ASIN) + errno = 0; +#endif // !(HAVE_COMPATIBLE_ASIN) + + ret = asin(x); + +#if !(HAVE_COMPATIBLE_ASIN) + if (errno == EDOM) + { + ret = NAN; + } +#endif // !(HAVE_COMPATIBLE_ASIN) + + LOGEXIT("Exit from asin: double return=%f\n", ret); + PERF_EXIT(asin); + return ret; +} + +/*++ +Function: + asinf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_asinf(float x) +{ + float ret; + PERF_ENTRY(asinf); + ENTRY("Entry to asinf: float x=%f\n", x); + +#if !(HAVE_COMPATIBLE_ASIN) + errno = 0; +#endif // !(HAVE_COMPATIBLE_ASIN) + + ret = asinf(x); + +#if !(HAVE_COMPATIBLE_ASIN) + if (errno == EDOM) + { + ret = NAN; + } +#endif // !(HAVE_COMPATIBLE_ASIN) + + LOGEXIT("Exit from asinf: float return=%f\n", ret); + PERF_EXIT(asinf); + return ret; +} + +/*++ +Function: + atan + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_atan(double x) +{ + double ret; + PERF_ENTRY(atan); + ENTRY("Entry to atan: double x=%f\n", x); + + ret = atan(x); + + LOGEXIT("Exit from atan: double return=%f\n", ret); + PERF_EXIT(atan); + return ret; +} + +/*++ +Function: + atanf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_atanf(float x) +{ + float ret; + PERF_ENTRY(atanf); + ENTRY("Entry to atanf: float x=%f\n", x); + + ret = atanf(x); + + LOGEXIT("Exit from atanf: float return=%f\n", ret); + PERF_EXIT(atanf); + return ret; +} + +/*++ +Function: + atan2 + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_atan2(double y, double x) +{ + double ret; + PERF_ENTRY(atan2); + ENTRY("Entry to atan2: double y=%f, double x=%f\n", y, x); + +#if !(HAVE_COMPATIBLE_ATAN2) + errno = 0; +#endif // !(HAVE_COMPATIBLE_ATAN2) + + ret = atan2(y, x); + +#if !(HAVE_COMPATIBLE_ATAN2) + if ((errno == EDOM) && (x == 0) && (y == 0))) + { + if (copysign(1, x) > 0) + { + ret = copysign(0, y); + } + else + { + ret = copysign(M_PI, y); + } + } +#endif // !(HAVE_COMPATIBLE_ATAN2) + + LOGEXIT("Exit from atan2: double return=%f\n", ret); + PERF_EXIT(atan2); + return ret; +} + +/*++ +Function: + atan2f + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_atan2f(float y, float x) +{ + float ret; + PERF_ENTRY(atan2f); + ENTRY("Entry to atan2f: float y=%f, float x=%f\n", y, x); + +#if !(HAVE_COMPATIBLE_ATAN2) + errno = 0; +#endif // !(HAVE_COMPATIBLE_ATAN2) + + ret = atan2f(y, x); + +#if !(HAVE_COMPATIBLE_ATAN2) + if ((errno == EDOM) && (x == 0) && (y == 0))) + { + if (copysign(1, x) > 0) + { + ret = copysign(0, y); + } + else + { + ret = copysign(M_PI, y); + } + } +#endif // !(HAVE_COMPATIBLE_ATAN2) + + LOGEXIT("Exit from atan2f: float return=%f\n", ret); + PERF_EXIT(atan2f); + return ret; +} + +/*++ +Function: + cos + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_cos(double x) +{ + double ret; + PERF_ENTRY(cos); + ENTRY("Entry to cos: double x=%f\n", x); + + ret = cos(x); + + LOGEXIT("Exit from cos: double return=%f\n", ret); + PERF_EXIT(cos); + return ret; +} + +/*++ +Function: + cosf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_cosf(float x) +{ + float ret; + PERF_ENTRY(cosf); + ENTRY("Entry to cosf: float x=%f\n", x); + + ret = cosf(x); + + LOGEXIT("Exit from cosf: double return=%f\n", ret); + PERF_EXIT(cosf); + return ret; +} + +/*++ +Function: + sin + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_sin(double x) +{ + double ret; + PERF_ENTRY(sin); + ENTRY("Entry to sin: double x=%f\n", x); + + ret = sin(x); + + LOGEXIT("Exit from sin: double return=%f\n", ret); + PERF_EXIT(sin); + return ret; +} + +/*++ +Function: + sinf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_sinf(float x) +{ + float ret; + PERF_ENTRY(sinf); + ENTRY("Entry to sinf: float x=%f\n", x); + + ret = sinf(x); + + LOGEXIT("Exit from sinf: float return=%f\n", ret); + PERF_EXIT(sinf); + return ret; +} + +/*++ +Function: + tan + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_tan(double x) +{ + double ret; + PERF_ENTRY(tan); + ENTRY("Entry to tan: double x=%f\n", x); + + ret = tan(x); + + LOGEXIT("Exit from tan: double return=%f\n", ret); + PERF_EXIT(tan); + return ret; +} + +/*++ +Function: + tanf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_tanf(float x) +{ + float ret; + PERF_ENTRY(tanf); + ENTRY("Entry to tanf: float x=%f\n", x); + + ret = tanf(x); + + LOGEXIT("Exit from tanf: float return=%f\n", ret); + PERF_EXIT(tanf); + return ret; +} + +// 7.12.5 Hyperbolic Functions +/*++ +Function: + acosh + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_acosh(double x) +{ + double ret; + PERF_ENTRY(acosh); + ENTRY("Entry to acosh: double x=%f\n", x); + + ret = acosh(x); + + LOGEXIT("Exit from acosh: double return=%f\n", ret); + PERF_EXIT(acosh); + return ret; +} + +/*++ +Function: + acoshf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_acoshf(float x) +{ + float ret; + PERF_ENTRY(acoshf); + ENTRY("Entry to acoshf: float x=%f\n", x); + + ret = acoshf(x); + + LOGEXIT("Exit from acoshf: float return=%f\n", ret); + PERF_EXIT(acoshf); + return ret; +} + +/*++ +Function: + asinh + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_asinh(double x) +{ + double ret; + PERF_ENTRY(asinh); + ENTRY("Entry to asinh: double x=%f\n", x); + + ret = asinh(x); + + LOGEXIT("Exit from asinh: double return=%f\n", ret); + PERF_EXIT(asinh); + return ret; +} + +/*++ +Function: + asinhf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_asinhf(float x) +{ + float ret; + PERF_ENTRY(asinhf); + ENTRY("Entry to asinhf: float x=%f\n", x); + + ret = asinhf(x); + + LOGEXIT("Exit from asinhf: float return=%f\n", ret); + PERF_EXIT(asinhf); + return ret; +} + +/*++ +Function: + atanh + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_atanh(double x) +{ + double ret; + PERF_ENTRY(atanh); + ENTRY("Entry to atanh: double x=%f\n", x); + + ret = atanh(x); + + LOGEXIT("Exit from atanh: double return=%f\n", ret); + PERF_EXIT(atanh); + return ret; +} + +/*++ +Function: + atanhf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_atanhf(float x) +{ + float ret; + PERF_ENTRY(atanhf); + ENTRY("Entry to atanhf: float x=%f\n", x); + + ret = atanhf(x); + + LOGEXIT("Exit from atanhf: float return=%f\n", ret); + PERF_EXIT(atanhf); + return ret; +} + +/*++ +Function: + cosh + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_cosh(double x) +{ + double ret; + PERF_ENTRY(cosh); + ENTRY("Entry to cosh: double x=%f\n", x); + + ret = cosh(x); + + LOGEXIT("Exit from cosh: double return=%f\n", ret); + PERF_EXIT(cosh); + return ret; +} + +/*++ +Function: + coshf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_coshf(float x) +{ + float ret; + PERF_ENTRY(coshf); + ENTRY("Entry to coshf: float x=%f\n", x); + + ret = coshf(x); + + LOGEXIT("Exit from coshf: double return=%f\n", ret); + PERF_EXIT(coshf); + return ret; +} + +/*++ +Function: + sinh + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_sinh(double x) +{ + double ret; + PERF_ENTRY(sinh); + ENTRY("Entry to sinh: double x=%f\n", x); + + ret = sinh(x); + + LOGEXIT("Exit from sinh: double return=%f\n", ret); + PERF_EXIT(sinh); + return ret; +} + +/*++ +Function: + sinhf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_sinhf(float x) +{ + float ret; + PERF_ENTRY(sinhf); + ENTRY("Entry to sinhf: float x=%f\n", x); + + ret = sinhf(x); + + LOGEXIT("Exit from sinhf: float return=%f\n", ret); + PERF_EXIT(sinhf); + return ret; +} + +/*++ +Function: + tanh + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_tanh(double x) +{ + double ret; + PERF_ENTRY(tanh); + ENTRY("Entry to tanh: double x=%f\n", x); + + ret = tanh(x); + + LOGEXIT("Exit from tanh: double return=%f\n", ret); + PERF_EXIT(tanh); + return ret; +} + +/*++ +Function: + tanhf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_tanhf(float x) +{ + float ret; + PERF_ENTRY(tanhf); + ENTRY("Entry to tanhf: float x=%f\n", x); + + ret = tanhf(x); + + LOGEXIT("Exit from tanhf: float return=%f\n", ret); + PERF_EXIT(tanhf); + return ret; +} + +// 7.12.6 Exponential and Logarithmic Functions +/*++ +Function: + exp + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_exp(double x) +{ + double ret; + PERF_ENTRY(exp); + ENTRY("Entry to exp: double x=%f\n", x); + +#if !(HAVE_COMPATIBLE_EXP) + if (x == 1) + { + ret = M_E; + } + else + { +#endif // !(HAVE_COMPATIBLE_EXP) + + ret = exp(x); + +#if !HAVE_COMPATIBLE_EXP + } +#endif // !(HAVE_COMPATIBLE_EXP) + + LOGEXIT("Exit from exp: double return=%f\n", ret); + PERF_EXIT(exp); + return ret; +} + +/*++ +Function: + expf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_expf(float x) +{ + float ret; + PERF_ENTRY(expf); + ENTRY("Entry to expf: float x=%f\n", x); + +#if !(HAVE_COMPATIBLE_EXP) + if (x == 1) + { + ret = M_E; + } + else + { +#endif // !(HAVE_COMPATIBLE_EXP) + + ret = expf(x); + +#if !HAVE_COMPATIBLE_EXP + } +#endif // !(HAVE_COMPATIBLE_EXP) + + LOGEXIT("Exit from expf: float return=%f\n", ret); + PERF_EXIT(expf); + return ret; +} + +/*++ +Function: + exp2 + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_exp2(double x) +{ + double ret; + PERF_ENTRY(exp2); + ENTRY("Entry to exp2: double x=%f\n", x); + + ret = exp2(x); + + LOGEXIT("Exit from exp2: double return=%f\n", ret); + PERF_EXIT(exp2); + return ret; +} + +/*++ +Function: + exp2f + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_exp2f(float x) +{ + float ret; + PERF_ENTRY(exp2f); + ENTRY("Entry to exp2f: float x=%f\n", x); + + ret = exp2f(x); + + LOGEXIT("Exit from exp2f: float return=%f\n", ret); + PERF_EXIT(exp2f); + return ret; +} + +/*++ +Function: + expm1 + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_expm1(double x) +{ + double ret; + PERF_ENTRY(expm1); + ENTRY("Entry to expm1: double x=%f\n", x); + + ret = expm1(x); + + LOGEXIT("Exit from expm1: double return=%f\n", ret); + PERF_EXIT(expm1); + return ret; +} + +/*++ +Function: + expm1f + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_expm1f(float x) +{ + float ret; + PERF_ENTRY(expm1f); + ENTRY("Entry to expm1f: float x=%f\n", x); + + ret = expm1f(x); + + LOGEXIT("Exit from expm1f: float return=%f\n", ret); + PERF_EXIT(expm1f); + return ret; +} + +/*++ +Function: + frexp + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_frexp(double value, int* exp) +{ + double ret; + PERF_ENTRY(frexp); + ENTRY("Entry to frexp: double value=%f, int* exp=%p\n", value, exp); + + ret = frexp(value, exp); + + LOGEXIT("Exit from frexp: double return=%f, *exp=%d\n", ret, *exp); + PERF_EXIT(frexp); + return ret; +} + +/*++ +Function: + frexpf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_frexpf(float value, int* exp) +{ + float ret; + PERF_ENTRY(frexpf); + ENTRY("Entry to frexpf: float value=%f, int* exp=%p\n", value, exp); + + ret = frexpf(value, exp); + + LOGEXIT("Exit from frexpf: float return=%f, *exp=%d\n", ret, *exp); + PERF_EXIT(frexpf); + return ret; +} + +/*++ +Function: + ldexp + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_ldexp(double x, int exp) +{ + double ret; + PERF_ENTRY(ldexp); + ENTRY("Entry to ldexp: double x=%f, int exp=%d\n", x, exp); + + ret = ldexp(x, exp); + + LOGEXIT("Exit from ldexp: double return=%f\n", ret); + PERF_EXIT(ldexp); + return ret; +} + +/*++ +Function: + ldexpf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_ldexpf(float x, int exp) +{ + float ret; + PERF_ENTRY(ldexpf); + ENTRY("Entry to ldexpf: float x=%f, int exp=%d\n", x, exp); + + ret = ldexpf(x, exp); + + LOGEXIT("Exit from ldexpf: float return=%f\n", ret); + PERF_EXIT(ldexpf); + return ret; +} + +/*++ +Function: + log + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_log(double x) +{ + double ret; + PERF_ENTRY(log); + ENTRY("Entry to log: double x=%f\n", x); + +#if !(HAVE_COMPATIBLE_LOG) + errno = 0; +#endif // !(HAVE_COMPATIBLE_LOG) + + ret = log(x); + +#if !(HAVE_COMPATIBLE_LOG) + if ((errno == EDOM) && (x < 0)) + { + ret = NAN; + } +#endif // !(HAVE_COMPATIBLE_LOG) + + LOGEXIT("Exit from log: double return=%f\n", ret); + PERF_EXIT(log); + return ret; +} + +/*++ +Function: + logf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_logf(float x) +{ + float ret; + PERF_ENTRY(logf); + ENTRY("Entry to logf: float x=%f\n", x); + +#if !(HAVE_COMPATIBLE_LOG) + errno = 0; +#endif // !(HAVE_COMPATIBLE_LOG) + + ret = logf(x); + +#if !(HAVE_COMPATIBLE_LOG) + if ((errno == EDOM) && (x < 0)) + { + ret = NAN; + } +#endif // !(HAVE_COMPATIBLE_LOG) + + LOGEXIT("Exit from logf: float return=%f\n", ret); + PERF_EXIT(logf); + return ret; +} + +/*++ +Function: + log10 + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_log10(double x) +{ + double ret; + PERF_ENTRY(log10); + ENTRY("Entry to log10: double x=%f\n", x); + +#if !(HAVE_COMPATIBLE_LOG10) + errno = 0; +#endif // !(HAVE_COMPATIBLE_LOG10) + + ret = log10(x); + +#if !(HAVE_COMPATIBLE_LOG10) + if ((errno == EDOM) && (x < 0)) + { + ret = NAN; + } +#endif // !(HAVE_COMPATIBLE_LOG10) + + LOGEXIT("Exit from log10: double return=%f\n", ret); + PERF_EXIT(log10); + return ret; +} + +/*++ +Function: + log10f + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_log10f(float x) +{ + float ret; + PERF_ENTRY(log10f); + ENTRY("Entry to log10f: float x=%f\n", x); + +#if !(HAVE_COMPATIBLE_LOG10) + errno = 0; +#endif // !(HAVE_COMPATIBLE_LOG10) + + ret = log10f(x); + +#if !(HAVE_COMPATIBLE_LOG10) + if ((errno == EDOM) && (x < 0)) + { + ret = NAN; + } +#endif // !(HAVE_COMPATIBLE_LOG10) + + LOGEXIT("Exit from log10f: float return=%f\n", ret); + PERF_EXIT(log10f); + return ret; +} + +/*++ +Function: + log1p + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_log1p(double x) +{ + double ret; + PERF_ENTRY(log1p); + ENTRY("Entry to log1p: double x=%f\n", x); + + ret = log1p(x); + + LOGEXIT("Exit from log1p: double return=%f\n", ret); + PERF_EXIT(log1p); + return ret; +} + +/*++ +Function: + log1pf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_log1pf(float x) +{ + float ret; + PERF_ENTRY(log1pf); + ENTRY("Entry to log1pf: float x=%f\n", x); + + ret = log1pf(x); + + LOGEXIT("Exit from log1pf: float return=%f\n", ret); + PERF_EXIT(log1pf); + return ret; +} + +/*++ +Function: + log2 + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_log2(double x) +{ + double ret; + PERF_ENTRY(log2); + ENTRY("Entry to log2: double x=%f\n", x); + + ret = log2(x); + + LOGEXIT("Exit from log2: double return=%f\n", ret); + PERF_EXIT(log2); + return ret; +} + +/*++ +Function: + log2f + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_log2f(float x) +{ + float ret; + PERF_ENTRY(log2f); + ENTRY("Entry to log2f: float x=%f\n", x); + + ret = log2f(x); + + LOGEXIT("Exit from log2f: float return=%f\n", ret); + PERF_EXIT(log2f); + return ret; +} + +/*++ +Function: + modf + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_modf(double value, double* iptr) +{ + double ret; + PERF_ENTRY(modf); + ENTRY("Entry to modf: double value=%f, double* iptr=%p\n", value, iptr); + + ret = modf(value, iptr); + + LOGEXIT("Exit from modf: double return=%f, *iptr=%f\n", ret, *iptr); + PERF_EXIT(modf); + return ret; +} + +/*++ +Function: + modff + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_modff(float value, float* iptr) +{ + float ret; + PERF_ENTRY(modff); + ENTRY("Entry to modff: float value=%f, float* iptr=%p\n", value, iptr); + + ret = modff(value, iptr); + + LOGEXIT("Exit from modff: double return=%f, *iptr=%f\n", ret, *iptr); + PERF_EXIT(modff); + return ret; +} + +/*++ +Function: + scalbn + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_scalbn(double x, int n) +{ + double ret; + PERF_ENTRY(scalbn); + ENTRY("Entry to scalbn: double x=%f, int n=%d\n", x, n); + + ret = scalbn(x, n); + + LOGEXIT("Exit from scalbn: double return=%f\n", ret); + PERF_EXIT(scalbn); + return ret; +} + +/*++ +Function: + scalbnf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_scalbnf(float x, int n) +{ + float ret; + PERF_ENTRY(scalbnf); + ENTRY("Entry to scalbnf: float x=%f, int n=%d\n", x, n); + + ret = scalbnf(x, n); + + LOGEXIT("Exit from scalbnf: float return=%f\n", ret); + PERF_EXIT(scalbnf); + return ret; +} + +// 7.12.7 Power and Absolute-Value Functions +/*++ +Function: + cbrt + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_cbrt(double x) +{ + double ret; + PERF_ENTRY(cbrt); + ENTRY("Entry to cbrt: double x=%f\n", x); + + ret = cbrt(x); + + LOGEXIT("Exit from cbrt: double return=%f\n", ret); + PERF_EXIT(cbrt); + return ret; +} + +/*++ +Function: + cbrtf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_cbrtf(float x) +{ + float ret; + PERF_ENTRY(cbrtf); + ENTRY("Entry to cbrtf: float x=%f\n", x); + + ret = cbrtf(x); + + LOGEXIT("Exit from cbrtf: float return=%f\n", ret); + PERF_EXIT(cbrtf); + return ret; +} + +/*++ +Function: + fabs + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_fabs(double x) +{ + double ret; + PERF_ENTRY(fabs); + ENTRY("Entry to fabs: double x=%f\n", x); + + ret = fabs(x); + + LOGEXIT("Exit from fabs: double return=%f\n", ret); + PERF_EXIT(fabs); + return ret; +} + +/*++ +Function: + fabsf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_fabsf(float x) +{ + float ret; + PERF_ENTRY(fabsf); + ENTRY("Entry to fabsf: float x=%f\n", x); + + ret = fabsf(x); + + LOGEXIT("Exit from fabsf: float return=%f\n", ret); + PERF_EXIT(fabsf); + return ret; +} + +/*++ +Function: + hypot + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_hypot(double x, double y) +{ + double ret; + PERF_ENTRY(hypot); + ENTRY("Entry to hypot: double x=%f, double y=%f\n", x, y); + + ret = hypot(x, y); + + LOGEXIT("Exit from hypot: double return=%f\n", ret); + PERF_EXIT(hypot); + return ret; +} + +/*++ +Function: + hypotf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_hypotf(float x, float y) +{ + float ret; + PERF_ENTRY(hypotf); + ENTRY("Entry to hypotf: float x=%f, float y=%f\n", x, y); + + ret = hypotf(x, y); + + LOGEXIT("Exit from hypotf: float return=%f\n", ret); + PERF_EXIT(hypotf); + return ret; +} + +/*++ +Function: + pow + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_pow(double x, double y) +{ + double ret; + PERF_ENTRY(pow); + ENTRY("Entry to pow: double x=%f, double y=%f\n", x, y); + +#if !(HAVE_COMPATIBLE_POW) + if (isinf(y) && !isnan(x)) + { + if ((x == 1) || (x == -1)) + { + ret = NAN; + } + else if ((x > -1) && (x < 1)) + { + ret = (y == INFINITY) ? 0 : INFINITY; + } + else + { + ret = (y == INFINITY) ? INFINITY : 0; + } + } + else +#endif // !(HAVE_COMPATIBLE_POW) + + if ((y == 0) && isnan(x)) + { + // Windows returns NaN for pow(NaN, 0), but POSIX specifies + // a return value of 1 for that case. We need to return + // the same result as Windows. + ret = NAN; + } + else + { + ret = pow(x, y); + } + +#if !(HAVE_VALID_NEGATIVE_INF_POW) && HAVE_VALID_POSITIVE_INF_POW + if ((ret == INFINITY) && (x < 0) && isfinite(x) && (ceil(y / 2) != floor(y / 2))) + { + ret = -INFINITY; + } +#endif // !(HAVE_VALID_NEGATIVE_INF_POW) + +#if !(HAVE_VALID_POSITIVE_INF_POW) + /* + * The even/odd test in the if (this one and the one above) used to be ((long long) y % 2 == 0) + * on SPARC (long long) y for large y (>2**63) is always 0x7fffffff7fffffff, which + * is an odd number, so the test ((long long) y % 2 == 0) will always fail for + * large y. Since large double numbers are always even (e.g., the representation of + * 1E20+1 is the same as that of 1E20, the last .+1. is too insignificant to be part + * of the representation), this test will always return the wrong result for large y. + * + * The (ceil(y / 2) == floor(y / 2)) test is slower, but more robust. + */ + if ((ret == -INFINITY) && (x < 0) && isfinite(x) && ceil(y / 2) == floor(y / 2)) + { + ret = INFINITY; + } +#endif // !(HAVE_VALID_POSITIVE_INF_POW) + + LOGEXIT("Exit from pow: double return=%f\n", ret); + PERF_EXIT(pow); + return ret; +} + +/*++ +Function: + powf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_powf(float x, float y) +{ + float ret; + PERF_ENTRY(powf); + ENTRY("Entry to powf: float x=%f, float y=%f\n", x, y); + +#if !(HAVE_COMPATIBLE_POW) + if (isinf(y) && !isnan(x)) + { + if ((x == 1) || (x == -1)) + { + ret = NAN; + } + else if ((x > -1) && (x < 1)) + { + ret = (y == INFINITY) ? 0 : INFINITY; + } + else + { + ret = (y == INFINITY) ? INFINITY : 0; + } + } + else +#endif // !(HAVE_COMPATIBLE_POW) + + if ((y == 0) && isnan(x)) + { + // Windows returns NaN for pow(NaN, 0), but POSIX specifies + // a return value of 1 for that case. We need to return + // the same result as Windows. + ret = NAN; + } + else + { + ret = powf(x, y); + } + +#if !(HAVE_VALID_NEGATIVE_INF_POW) && HAVE_VALID_POSITIVE_INF_POW + if ((ret == INFINITY) && (x < 0) && isfinite(x) && (ceil(y / 2) != floor(y / 2))) + { + ret = -INFINITY; + } +#endif // !(HAVE_VALID_NEGATIVE_INF_POW) + +#if !(HAVE_VALID_POSITIVE_INF_POW) + /* + * The even/odd test in the if (this one and the one above) used to be ((long long) y % 2 == 0) + * on SPARC (long long) y for large y (>2**63) is always 0x7fffffff7fffffff, which + * is an odd number, so the test ((long long) y % 2 == 0) will always fail for + * large y. Since large double numbers are always even (e.g., the representation of + * 1E20+1 is the same as that of 1E20, the last .+1. is too insignificant to be part + * of the representation), this test will always return the wrong result for large y. + * + * The (ceil(y / 2) == floor(y / 2)) test is slower, but more robust. + */ + if ((ret == -INFINITY) && (x < 0) && isfinite(x) && ceil(y / 2) == floor(y / 2)) + { + ret = INFINITY; + } +#endif // !(HAVE_VALID_POSITIVE_INF_POW) + + LOGEXIT("Exit from powf: float return=%f\n", ret); + PERF_EXIT(powf); + return ret; +} + +/*++ +Function: + sqrt + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_sqrt(double x) +{ + double ret; + PERF_ENTRY(sqrt); + ENTRY("Entry to sqrt: double x=%f\n", x); + + ret = sqrt(x); + + LOGEXIT("Exit from sqrt: double return=%f\n", ret); + PERF_EXIT(sqrt); + return ret; +} + +/*++ +Function: + sqrtf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_sqrtf(float x) +{ + float ret; + PERF_ENTRY(sqrtf); + ENTRY("Entry to sqrtf: float x=%f\n", x); + + ret = sqrtf(x); + + LOGEXIT("Exit from sqrtf: float return=%f\n", ret); + PERF_EXIT(sqrtf); + return ret; +} + +// 7.12.8 Error and Gamma Functions +/*++ +Function: + erf + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_erf(double x) +{ + double ret; + PERF_ENTRY(erf); + ENTRY("Entry to erf: double x=%f\n", x); + + ret = erf(x); + + LOGEXIT("Exit from erf: double return=%f\n", ret); + PERF_EXIT(erf); + return ret; +} + +/*++ +Function: + erff + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_erff(float x) +{ + float ret; + PERF_ENTRY(erff); + ENTRY("Entry to erff: float x=%f\n", x); + + ret = erff(x); + + LOGEXIT("Exit from erff: float return=%f\n", ret); + PERF_EXIT(erff); + return ret; +} + +/*++ +Function: + erfc + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_erfc(double x) +{ + double ret; + PERF_ENTRY(erfc); + ENTRY("Entry to erfc: double x=%f\n", x); + + ret = erfc(x); + + LOGEXIT("Exit from erfc: double return=%f\n", ret); + PERF_EXIT(erfc); + return ret; +} + +/*++ +Function: + erfcf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_erfcf(float x) +{ + float ret; + PERF_ENTRY(erfcf); + ENTRY("Entry to erfcf: float x=%f\n", x); + + ret = erfcf(x); + + LOGEXIT("Exit from erfcf: float return=%f\n", ret); + PERF_EXIT(erfcf); + return ret; +} + +/*++ +Function: + lgamma + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_lgamma(double x) +{ + double ret; + PERF_ENTRY(lgamma); + ENTRY("Entry to lgamma: double x=%f\n", x); + + ret = lgamma(x); + + LOGEXIT("Exit from lgamma: double return=%f\n", ret); + PERF_EXIT(lgamma); + return ret; +} + +/*++ +Function: + lgammaf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_lgammaf(float x) +{ + float ret; + PERF_ENTRY(lgammaf); + ENTRY("Entry to lgammaf: float x=%f\n", x); + + ret = lgammaf(x); + + LOGEXIT("Exit from lgammaf: float return=%f\n", ret); + PERF_EXIT(lgammaf); + return ret; +} + +/*++ +Function: + tgamma + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_tgamma(double x) +{ + double ret; + PERF_ENTRY(tgamma); + ENTRY("Entry to tgamma: double x=%f\n", x); + + ret = tgamma(x); + + LOGEXIT("Exit from tgamma: double return=%f\n", ret); + PERF_EXIT(tgamma); + return ret; +} + +/*++ +Function: + tgammaf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_tgammaf(float x) +{ + float ret; + PERF_ENTRY(tgammaf); + ENTRY("Entry to tgammaf: float x=%f\n", x); + + ret = tgammaf(x); + + LOGEXIT("Exit from tgammaf: float return=%f\n", ret); + PERF_EXIT(tgammaf); + return ret; +} + +// 7.12.9 Nearest Integer Functions +/*++ +Function: + ceil + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_ceil(double x) +{ + double ret; + PERF_ENTRY(ceil); + ENTRY("Entry to ceil: double x=%f\n", x); + + ret = ceil(x); + + LOGEXIT("Exit from ceil: double return=%f\n", ret); + PERF_EXIT(ceil); + return ret; +} + +/*++ +Function: + ceilf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_ceilf(float x) +{ + float ret; + PERF_ENTRY(ceilf); + ENTRY("Entry to ceilf: float x=%f\n", x); + + ret = ceilf(x); + + LOGEXIT("Exit from ceilf: float return=%f\n", ret); + PERF_EXIT(ceilf); + return ret; +} + +/*++ +Function: + floor + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_floor(double x) +{ + double ret; + PERF_ENTRY(floor); + ENTRY("Entry to floor: double x=%f\n", x); + + ret = floor(x); + + LOGEXIT("Exit from floor: double return=%f\n", ret); + PERF_EXIT(floor); + return ret; +} + +/*++ +Function: + floorf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_floorf(float x) +{ + float ret; + PERF_ENTRY(floorf); + ENTRY("Entry to floorf: float x=%f\n", x); + + ret = floorf(x); + + LOGEXIT("Exit from floorf: float return=%f\n", ret); + PERF_EXIT(floorf); + return ret; +} + +// 7.12.10 Remainder Functions +/*++ +Function: + fmod + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_fmod(double x, double y) +{ + double ret; + PERF_ENTRY(fmod); + ENTRY("Entry to fmod: double x=%f, double y=%f\n", x, y); + + ret = fmod(x, y); + + LOGEXIT("Exit from fmod: double return=%f\n", ret); + PERF_EXIT(fmod); + return ret; +} + +/*++ +Function: + fmodf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_fmodf(float x, float y) +{ + float ret; + PERF_ENTRY(fmodf); + ENTRY("Entry to fmodf: float x=%f, float y=%f\n", x, y); + + ret = fmodf(x, y); + + LOGEXIT("Exit from fmodf: float return=%f\n", ret); + PERF_EXIT(fmodf); + return ret; +} + +/*++ +Function: + remquo + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_remquo(double x, double y, int* quo) +{ + double ret; + PERF_ENTRY(remquo); + ENTRY("Entry to remquo: double x=%f, double y=%f, int* quo=%p\n", x, y, quo); + + ret = remquo(x, y, quo); + + LOGEXIT("Exit from remquo: double return=%f, *quo=%d\n", ret, *quo); + PERF_EXIT(remquo); + return ret; +} + +/*++ +Function: + remquof + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_remquo(float x, float y, int* quo) +{ + float ret; + PERF_ENTRY(remquof); + ENTRY("Entry to remquof: float x=%f, float y=%f, int* quo=%p\n", x, y, quo); + + ret = remquof(x, y, quo); + + LOGEXIT("Exit from remquof: float return=%f, *quo=%d\n", ret, *quo); + PERF_EXIT(remquof); + return ret; +} + +// 7.12.11 Manipulation Functions +/*++ +Function: + copysign + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_copysign(double x, double y) +{ + double ret; + PERF_ENTRY(copysign); + ENTRY("Entry to copysign: double x=%f, double y=%f\n", x, y); + + ret = copysign(x, y); + + LOGEXIT("Exit from copysign: double return=%f\n", ret); + PERF_EXIT(copysign); + return ret; +} + +/*++ +Function: + copysignf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_copysignf(float x, float y) +{ + float ret; + PERF_ENTRY(copysignf); + ENTRY("Entry to copysignf: float x=%f, float y=%f\n", x, y); + + ret = copysignf(x, y); + + LOGEXIT("Exit from copysignf: float return=%f\n", ret); + PERF_EXIT(copysignf); + return ret; +} + +/*++ +Function: + nextafter + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_nextafter(double x, double y) +{ + double ret; + PERF_ENTRY(nextafter); + ENTRY("Entry to nextafter: double x=%f, double y=%f\n", x, y); + + ret = nextafter(x, y); + + LOGEXIT("Exit from nextafter: double return=%f\n", ret); + PERF_EXIT(nextafter); + return ret; +} + +/*++ +Function: + nextafterf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_nextafterf(float x, float y) +{ + float ret; + PERF_ENTRY(nextafterf); + ENTRY("Entry to nextafterf: float x=%f, float y=%f\n", x, y); + + ret = nextafterf(x, y); + + LOGEXIT("Exit from nextafterf: float return=%f\n", ret); + PERF_EXIT(nextafterf); + return ret; +} + +// 7.12.13 Floating Multiply-Add Function +/*++ +Function: + fma + +See MSDN. +--*/ +PALIMPORT double __cdecl PAL_fma(double x, double y, double z) +{ + double ret; + PERF_ENTRY(fma); + ENTRY("Entry to fma: double x=%f, double y=%f, double z=%f\n", x, y, z); + + ret = fma(x, y, z); + + LOGEXIT("Exit from fma: double return=%f\n", ret); + PERF_EXIT(fma); + return ret; +} + +/*++ +Function: + fmaf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_fmaf(float x, float y, float z) +{ + float ret; + PERF_ENTRY(fmaf); + ENTRY("Entry to fmaf: float x=%f, float y=%f, float z=%f\n", x, y, z); + + ret = fmaf(x, y, z); + + LOGEXIT("Exit from fmaf: float return=%f\n", ret); + PERF_EXIT(fmaf); + return ret; +} diff --git a/src/pal/src/include/pal/palinternal.h b/src/pal/src/include/pal/palinternal.h index 4ea8c3bc2d41..26d2f11c76f7 100644 --- a/src/pal/src/include/pal/palinternal.h +++ b/src/pal/src/include/pal/palinternal.h @@ -204,23 +204,189 @@ function_name() to call the system's implementation #define time_t PAL_time_t #define va_list DUMMY_va_list #define abs DUMMY_abs +#define labs DUMMY_labs #define llabs DUMMY_llabs -#define atan DUMMY_atan -#define tan DUMMY_tan -#define cos DUMMY_cos -#define sin DUMMY_sin -#define cosh DUMMY_cosh -#define sinh DUMMY_sinh -#define tanh DUMMY_tanh -#define modf DUMMY_modf -#define fmod DUMMY_fmod -#define fmodf DUMMY_fmodf -#define sqrt DUMMY_sqrt -#define ceil DUMMY_ceil -#define fabs DUMMY_fabs -#define fabsf DUMMY_fabsf -#define floor DUMMY_floor -#define modff DUMMY_modff + +// 7.12.4 Trigonometric Functions +#define acos DUMMY_acos +#define acosf DUMMY_acosf + +#define asin DUMMY_asin +#define asinf DUMMY_asinf + +#define atan DUMMY_atan +#define atanf DUMMY_atanf + +#define atan2 DUMMY_atan2 +#define atan2f DUMMY_atan2f + +#define cos DUMMY_cos +#define cosf DUMMY_cosf + +#define sin DUMMY_sin +#define sinf DUMMY_sinf + +#define tan DUMMY_tan +#define tanf DUMMY_tanf + +// 7.12.5 Hyperbolic Functions +#define acosh DUMMY_acosh +#define acoshf DUMMY_acoshf + +#define asinh DUMMY_asinh +#define asinhf DUMMY_asinhf + +#define atanh DUMMY_atanh +#define atanhf DUMMY_atanhf + +#define cosh DUMMY_cosh +#define coshf DUMMY_coshf + +#define sinh DUMMY_sinh +#define sinhf DUMMY_sinhf + +#define tanh DUMMY_tanh +#define tanhf DUMMY_tanhf + +// 7.12.6 Exponential and Logarithmic Functions +#define exp DUMMY_exp +#define expf DUMMY_expm1 + +#define exp2 DUMMY_exp2 +#define exp2f DUMMY_exp2f + +#define expm1 DUMMY_expm1 +#define expm1f DUMMY_expm1f + +#define frexp DUMMY_frexp +#define frexpf DUMMY_frexpf + +#define ilogb DUMMY_ilogb +#define ilogbf DUMMY_ilogbf + +#define ldexp DUMMY_ldexp +#define ldexpf DUMMY_ldexpf + +#define log DUMMY_log +#define logf DUMMY_logf + +#define log10 DUMMY_log10 +#define log10f DUMMY_log10f + +#define log1p DUMMY_log1p +#define log1pf DUMMY_log1pf + +#define log2 DUMMY_log2 +#define log2f DUMMY_log2f + +#define logb DUMMY_logb +#define logbf DUMMY_logbf + +#define modf DUMMY_modf +#define modff DUMMY_modff + +#define scalbn DUMMY_scalbn +#define scalbnf DUMMY_scalbnf + +#define scalbln DUMMY_scalbln +#define scalblnf DUMMY_scalblnf + +// 7.12.7 Power and Absolute-Value Functions +#define cbrt DUMMY_cbrt +#define cbrtf DUMMY_cbrtf + +#define fabs DUMMY_fabs +#define fabsf DUMMY_fabsf + +#define hypot DUMMY_hypot +#define hypotf DUMMY_hypotf + +#define pow DUMMY_pow +#define powf DUMMY_powf + +#define sqrt DUMMY_sqrt +#define sqrtf DUMMY_sqrtf + +// 7.12.8 Error and Gamma Functions +#define erf DUMMY_erf +#define erff DUMMY_erff + +#define erfc DUMMY_erfc +#define erfcf DUMMY_erfcf + +#define lgamma DUMMY_lgamma +#define lgammaf DUMMY_lgammaf + +#define tgamma DUMMY_tgamma +#define tgammaf DUMMY_tgammaf + +// 7.12.9 Nearest Integer Functions +#define ceil DUMMY_ceil +#define ceilf DUMMY_ceilf + +#define floor DUMMY_floor +#define floorf DUMMY_floorf + +#define nearbyint DUMMY_nearbyint +#define nearbyintf DUMMY_nearbyintf + +#define rint DUMMY_rint +#define rintf DUMMY_rintf + +#define lrint DUMMY_lrint +#define lrintf DUMMY_lrintf + +#define llrint DUMMY_llrint +#define llrintf DUMMY_llrintf + +#define round DUMMY_round +#define roundf DUMMY_roundf + +#define lround DUMMY_lround +#define lroundf DUMMY_lroundf + +#define llround DUMMY_llround +#define llroundf DUMMY_llroundf + +#define trunc DUMMY_trunc +#define truncf DUMMY_truncf + +// 7.12.10 Remainder Functions +#define fmod DUMMY_fmod +#define fmodf DUMMY_fmodf + +#define remainder DUMMY_remainder +#define remainderf DUMMY_remainderf + +#define remquo DUMMY_remquo +#define remquof DUMMY_remquof + +// 7.12.11 Manipulation Functions +#define copysign DUMMY_copysign +#define copysignf DUMMY_copysignf + +#define nan DUMMY_nan +#define nanf DUMMY_nanf + +#define nextafter DUMMY_nextafter +#define nextafterf DUMMY_nextafterf + +#define nexttoward DUMMY_nexttoward +#define nexttowardf DUMMY_nexttoward + +// 7.12.12 Maximum, Minimum, and Positive Difference Functions +#define fdim DUMMY_fdim +#define fdimf DUMMY_fdimf + +#define fmax DUMMY_fmax +#define fmaxf DUMMY_fmaxf + +#define fmin DUMMY_fmin +#define fminf DUMMY_fminf + +// 7.12.13 Floating Multiply-Add Function +#define fma DUMMY_fma +#define fmaf DUMMY_fmaf /* RAND_MAX needed to be renamed to avoid duplicate definition when including stdlib.h header files. PAL_RAND_MAX should have the same value as RAND_MAX @@ -439,13 +605,6 @@ function_name() to call the system's implementation #undef abs #undef labs #undef llabs -#undef acos -#undef asin -#undef atan2 -#undef exp -#undef log -#undef log10 -#undef pow #undef rand #undef srand #undef errno @@ -453,22 +612,196 @@ function_name() to call the system's implementation #undef wcsspn #undef open #undef glob + +// 7.12.0 General Macros +#undef INFINITY +#undef NAN + +// 7.12.3 Classification Macros +#undef isfinite +#undef isinf +#undef isnan + +// 7.12.4 Trigonometric Functions +#undef acos +#undef acosf + +#undef asin +#undef asinf + #undef atan -#undef tan +#undef atanf + +#undef atan2 +#undef atan2f + #undef cos +#undef cosf + #undef sin +#undef sinf + +#undef tan +#undef tanf + +// 7.12.5 Hyperbolic Functions +#undef acosh +#undef acoshf + +#undef asinh +#undef asinhf + +#undef atanh +#undef atanhf + #undef cosh +#undef coshf + #undef sinh +#undef sinhf + #undef tanh +#undef tanhf + +// 7.12.6 Exponential and Logarithmic Functions +#undef exp +#undef expf + +#undef exp2 +#undef exp2f + +#undef expm1 +#undef expm1f + +#undef frexp +#undef frexpf + +#undef ilogb +#undef ilogbf + +#undef ldexp +#undef ldexpf + +#undef log +#undef logf + +#undef log10 +#undef log10f + +#undef log1p +#undef log1pf + +#undef log2 +#undef log2f + +#undef logb +#undef logbf + #undef modf -#undef fmod -#undef fmodf -#undef sqrt -#undef ceil +#undef modff + +#undef scalbn +#undef scalbnf + +#undef scalbln +#undef scalblnf + +// 7.12.7 Power and Absolute-Value Functions +#undef cbrt +#undef cbrtf + #undef fabs #undef fabsf + +#undef hypot +#undef hypotf + +#undef pow +#undef powf + +#undef sqrt +#undef sqrtf + +// 7.12.8 Error and Gamma Functions +#undef erf +#undef erff + +#undef erfc +#undef erfcf + +#undef lgamma +#undef lgammaf + +#undef tgamma +#undef tgammaf + +// 7.12.9 Nearest Integer Functions +#undef ceil +#undef ceilf + #undef floor -#undef modff +#undef floorf + +#undef nearbyint +#undef nearbyintf + +#undef rint +#undef rintf + +#undef lrint +#undef lrintf + +#undef llrint +#undef llrintf + +#undef round +#undef roundf + +#undef lround +#undef lroundf + +#undef llround +#undef llroundf + +#undef trunc +#undef truncf + +// 7.12.10 Remainder Functions +#undef fmod +#undef fmodf + +#undef remainder +#undef remainderf + +#undef remquo +#undef remquof + +// 7.12.11 Manipulation Functions +#undef copysign +#undef copysignf + +#undef nan +#undef nanf + +#undef nextafter +#undef nextafterf + +#undef nexttoward +#undef nexttowardf + +// 7.12.12 Maximum, Minimum, and Positive Difference Functions +#undef fdim +#undef fdimf + +#undef fmax +#undef fmaxf + +#undef fmin +#undef fminf + +// 7.12.13 Floating Multiply-Add Function +#undef fma +#undef fmaf #undef wchar_t #undef ptrdiff_t diff --git a/src/pal/tests/palsuite/c_runtime/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/CMakeLists.txt index 5bc2e1ee84a3..1edc5ae7f063 100644 --- a/src/pal/tests/palsuite/c_runtime/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/CMakeLists.txt @@ -2,16 +2,29 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(abs) add_subdirectory(acos) +add_subdirectory(acosf) +add_subdirectory(acosh) +add_subdirectory(acoshf) add_subdirectory(asin) +add_subdirectory(asinf) +add_subdirectory(asinh) +add_subdirectory(asinhf) add_subdirectory(atan) +add_subdirectory(atanf) +add_subdirectory(atanh) +add_subdirectory(atanhf) add_subdirectory(atan2) +add_subdirectory(atan2f) add_subdirectory(atof) add_subdirectory(atoi) add_subdirectory(atol) add_subdirectory(bsearch) add_subdirectory(ceil) +add_subdirectory(ceilf) add_subdirectory(cos) +add_subdirectory(cosf) add_subdirectory(cosh) +add_subdirectory(coshf) # TODO: make this test compile # add_subdirectory(ctime) @@ -19,14 +32,18 @@ add_subdirectory(cosh) add_subdirectory(errno) add_subdirectory(exit) add_subdirectory(exp) +add_subdirectory(expf) add_subdirectory(fabs) +add_subdirectory(fabsf) add_subdirectory(fclose) add_subdirectory(feof) add_subdirectory(ferror) add_subdirectory(fflush) add_subdirectory(fgets) add_subdirectory(floor) +add_subdirectory(floorf) add_subdirectory(fmod) +add_subdirectory(fmodf) add_subdirectory(fopen) add_subdirectory(fprintf) add_subdirectory(fputs) @@ -41,7 +58,10 @@ add_subdirectory(getenv) add_subdirectory(isalnum) add_subdirectory(isalpha) add_subdirectory(isdigit) +add_subdirectory(isfinite) +add_subdirectory(isinf) add_subdirectory(islower) +add_subdirectory(isnan) add_subdirectory(isprint) add_subdirectory(isspace) add_subdirectory(isupper) @@ -54,6 +74,7 @@ add_subdirectory(labs) add_subdirectory(llabs) add_subdirectory(localtime) add_subdirectory(log) +add_subdirectory(logf) add_subdirectory(log10) add_subdirectory(malloc) add_subdirectory(memchr) @@ -68,7 +89,9 @@ add_subdirectory(qsort) add_subdirectory(rand_srand) add_subdirectory(realloc) add_subdirectory(sin) +add_subdirectory(sinf) add_subdirectory(sinh) +add_subdirectory(sinhf) add_subdirectory(sprintf) add_subdirectory(sqrt) add_subdirectory(sscanf) @@ -91,7 +114,9 @@ add_subdirectory(strtoul) add_subdirectory(swprintf) add_subdirectory(swscanf) add_subdirectory(tan) +add_subdirectory(tanf) add_subdirectory(tanh) +add_subdirectory(tanhf) add_subdirectory(time) add_subdirectory(tolower) add_subdirectory(toupper) @@ -121,14 +146,12 @@ add_subdirectory(wprintf) add_subdirectory(_alloca) add_subdirectory(_ecvt) add_subdirectory(_fdopen) -add_subdirectory(_finite) add_subdirectory(_fullpath) # TODO: make this test compile # add_subdirectory(_gcvt) add_subdirectory(_getw) -add_subdirectory(_isnan) add_subdirectory(_itow) add_subdirectory(_makepath) add_subdirectory(_mbsdec) diff --git a/src/pal/tests/palsuite/c_runtime/acos/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acos/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/acos/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/acos/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/acos/test1/test1.c b/src/pal/tests/palsuite/c_runtime/acos/test1/test1.c index 5d95353a05c1..5536fbc3c543 100644 --- a/src/pal/tests/palsuite/c_runtime/acos/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/acos/test1/test1.c @@ -7,117 +7,106 @@ ** ** Source: test1.c ** -** Purpose: Test to ensure that acos returns correct values. +** Purpose: Test to ensure that acos return the correct values ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** _finite -** - ** **===========================================================================*/ #include -/* Error acceptance level to the 7th decimal */ -#define DELTA 0.0000001 - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; /** - * main - * - * executable entry point + * validate + * + * test validation function */ -INT __cdecl main(INT argc, CHAR **argv) +void __cdecl validate(double value, double expected, double variance) { - double pi = 3.1415926535; - int i; + double result = acos(value); - struct test tests[] = - { - /* Value test result */ - { 1, 0 }, - { 0.9, 0.451026811796 }, - { 0.8, 0.643501108793 }, - { 0.7, 0.795398830184 }, - { 0.6, 0.927295218002 }, - { 0.5, 1.047197551197 }, - { 0.4, 1.159279480727 }, - { 0.3, 1.266103672779 }, - { 0.2, 1.369438406005 }, - { 0.1, 1.470628905633 }, - { 0, pi/2.0 }, - { -0.1, 1.670963747956 }, - { -0.2, 1.772154247585 }, - { -0.3, 1.875488980810 }, - { -0.4, 1.982313172862 }, - { -0.5, 2.094395102393 }, - { -0.6, 2.214297435588 }, - { -0.7, 2.346193823406 }, - { -0.8, 2.498091544797 }, - { -0.9, 2.690565841794 }, - { -1, pi } - }; + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); - double outofrange[] = + if ((delta != 0) && (delta >= variance)) { - -864278.51, -1000.2, -2, 2, 10, 100, 1234567.8, 1.7e308 - }; + Fail("acos(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = acos(value); - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (!isnan(result)) { - return (FAIL); + Fail("acos(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); } +} - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = { - double result; - double testDelta; - - result = acos( tests[i].value ); + /* value expected variance */ + { -1, 3.1415926535897932, 0.00000000000001 }, // expected: pi + { -0.91173391478696510, 2.7182818284590452, 0.00000000000001 }, // expected: e + { -0.66820151019031295, 2.3025850929940457, 0.00000000000001 }, // expected: ln(10) + { 0, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 + { 0.12775121753523991, 1.4426950408889634, 0.00000000000001 }, // expected: log2(e) + { 0.15594369476537447, 1.4142135623730950, 0.00000000000001 }, // expected: sqrt(2) + { 0.42812514788535792, 1.1283791670955126, 0.00000000000001 }, // expected: 2 / sqrt(pi) + { 0.54030230586813972, 1, 0.00000000000001 }, + { 0.70710678118654752, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4, value: 1 / sqrt(2) + { 0.76024459707563015, 0.70710678118654752, 0.000000000000001 }, // expected: 1 / sqrt(2) + { 0.76923890136397213, 0.69314718055994531, 0.000000000000001 }, // expected: ln(2) + { 0.80410982822879171, 0.63661977236758134, 0.000000000000001 }, // expected: 2 / pi + { 0.90716712923909839, 0.43429448190325183, 0.000000000000001 }, // expected: log10(e) + { 0.94976571538163866, 0.31830988618379067, 0.000000000000001 }, // expected: 1 / pi + { 1, 0, 0.000000000000001 }, + }; - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "acos(%g) returned %20.10f" - " when it should have returned %20.10f", - tests[i].value, - result, - tests[i].result ); - } + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; } - for( i = 0; i < sizeof(outofrange) / sizeof(double); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - - result = acos( outofrange[i] ); - - /* The test is valid when the function returns an infinite result */ - if( _finite( result ) ) - { - Fail( "acos(%g) returned %20.10f" - " when it should have returned -1.#IND00000000", - outofrange[i], - result ); - } + validate(tests[i].value, tests[i].expected, tests[i].variance); } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); PAL_Terminate(); return PASS; diff --git a/src/pal/tests/palsuite/c_runtime/acos/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/acos/test1/testinfo.dat index b4002a789efa..e40b449df803 100644 --- a/src/pal/tests/palsuite/c_runtime/acos/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/acos/test1/testinfo.dat @@ -12,6 +12,3 @@ Description = Passes a series of values to the acos() function, = checking each for the expected result. Also checks = for proper handling of out-of-range values. - - - diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acosf/CMakeLists.txt similarity index 98% rename from src/pal/tests/palsuite/c_runtime/_isnan/CMakeLists.txt rename to src/pal/tests/palsuite/c_runtime/acosf/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/_isnan/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/acosf/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acosf/test1/CMakeLists.txt similarity index 53% rename from src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt rename to src/pal/tests/palsuite/c_runtime/acosf/test1/CMakeLists.txt index 8aca58a8dc54..264364743885 100644 --- a/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/acosf/test1/CMakeLists.txt @@ -6,13 +6,13 @@ set(SOURCES test1.c ) -add_executable(paltest_finite_test1 +add_executable(paltest_acosf_test1 ${SOURCES} ) -add_dependencies(paltest_finite_test1 coreclrpal) +add_dependencies(paltest_acosf_test1 coreclrpal) -target_link_libraries(paltest_finite_test1 +target_link_libraries(paltest_acosf_test1 pthread m coreclrpal diff --git a/src/pal/tests/palsuite/c_runtime/acosf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/acosf/test1/test1.c new file mode 100644 index 000000000000..9dbb3056aa45 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosf/test1/test1.c @@ -0,0 +1,113 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that acosf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = acosf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("acosf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = acosf(value); + + if (!isnan(result)) + { + Fail("acosf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { -1, 3.14159265f, 0.00001f }, // expected: pi + { -0.911733915f, 2.71828183f, 0.00001f }, // expected: e + { -0.668201510f, 2.30258509f, 0.00001f }, // expected: ln(10) + { 0, 1.57079633f, 0.00001f }, // expected: pi / 2 + { 0.127751218f, 1.44269504f, 0.00001f }, // expected: log2(e) + { 0.155943695f, 1.41421356f, 0.00001f }, // expected: sqrt(2) + { 0.428125148f, 1.12837917f, 0.00001f }, // expected: 2 / sqrt(pi) + { 0.540302306f, 1, 0.00001f }, + { 0.707106781f, 0.785398163f, 0.000001f }, // expected: pi / 4, value: 1 / sqrt(2) + { 0.760244597f, 0.707106781f, 0.000001f }, // expected: 1 / sqrt(2) + { 0.769238901f, 0.693147181f, 0.000001f }, // expected: ln(2) + { 0.804109828f, 0.636619772f, 0.000001f }, // expected: 2 / pi + { 0.907167129f, 0.434294482f, 0.000001f }, // expected: log10(e) + { 0.949765715f, 0.318309886f, 0.000001f }, // expected: 1 / pi + { 1, 0, 0.000001f }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/acosf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/acosf/test1/testinfo.dat new file mode 100644 index 000000000000..c4b47b8cf66e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = acosf +Name = Positive Test for acosf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the acosf() function, += checking each for the expfected result. Also checks += for proper handling of out-of-range values. diff --git a/src/pal/tests/palsuite/c_runtime/acosh/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acosh/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosh/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/acosh/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acosh/test1/CMakeLists.txt new file mode 100644 index 000000000000..3da46f296859 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosh/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_acosh_test1 + ${SOURCES} +) + +add_dependencies(paltest_acosh_test1 coreclrpal) + +target_link_libraries(paltest_acosh_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/acosh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/acosh/test1/test1.c new file mode 100644 index 000000000000..1f1bc15dd98e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosh/test1/test1.c @@ -0,0 +1,116 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that acosh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = acosh(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("acosh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = acosh(value); + + if (!isnan(result)) + { + Fail("acosh(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 1, 0, 0.000000000000001 }, + { 1.0510897883672876, 0.31830988618379067, 0.000000000000001 }, // expected: 1 / pi + { 1.0957974645564909, 0.43429448190325183, 0.000000000000001 }, // expected: log10(e) + { 1.2095794864199787, 0.63661977236758134, 0.000000000000001 }, // expected: 2 / pi + { 1.25, 0.69314718055994531, 0.000000000000001 }, // expected: ln(2) + { 1.2605918365213561, 0.70710678118654752, 0.000000000000001 }, // expected: 1 / sqrt(2) + { 1.3246090892520058, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4 + { 1.5430806348152438, 1, 0.00000000000001 }, + { 1.7071001431069344, 1.1283791670955126, 0.00000000000001 }, // expected: 2 / sqrt(pi) + { 2.1781835566085709, 1.4142135623730950, 0.00000000000001 }, // expected: sqrt(2) + { 2.2341880974508023, 1.4426950408889634, 0.00000000000001 }, // expected: log2(e) + { 2.5091784786580568, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 + { 5.05, 2.3025850929940457, 0.00000000000001 }, // expected: ln(10) + { 7.6101251386622884, 2.7182818284590452, 0.00000000000001 }, // expected: e + { 11.591953275521521, 3.1415926535897932, 0.00000000000001 }, // expected: pi + { INFINITY, INFINITY, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + + validate_isnan(-tests[i].value); + } + + validate_isnan( NAN); + validate_isnan( 0); + validate_isnan(-INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/acosh/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/acosh/test1/testinfo.dat new file mode 100644 index 000000000000..24670747bf52 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosh/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = acosh +Name = Positive Test for acosh +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to acosh() a series of values, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/acoshf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acoshf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acoshf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/acoshf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acoshf/test1/CMakeLists.txt new file mode 100644 index 000000000000..059bd74813e4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acoshf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_acoshf_test1 + ${SOURCES} +) + +add_dependencies(paltest_acoshf_test1 coreclrpal) + +target_link_libraries(paltest_acoshf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/acoshf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/acoshf/test1/test1.c new file mode 100644 index 000000000000..26d332a8425e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acoshf/test1/test1.c @@ -0,0 +1,132 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that acoshf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = acoshf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("acoshf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = acoshf(value); + + if (!isnan(result)) + { + Fail("acoshf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * validate + * + * test validation function for values returning +INF + */ +void __cdecl validate_isinf_positive(float value) +{ + float result = acoshf(value); + + if (result != INFINITY) + { + Fail("acoshf(%g) returned %10.9g when it should have returned %10.9g", + value, result, INFINITY); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 1, 0, 0.000001f }, + { 1.05108979f, 0.318309886f, 0.000001f }, // expected: 1 / pi + { 1.09579746f, 0.434294482f, 0.000001f }, // expected: log10(e) + { 1.20957949f, 0.636619772f, 0.000001f }, // expected: 2 / pi + { 1.25f, 0.693147181f, 0.000001f }, // expected: ln(2) + { 1.26059184f, 0.707106781f, 0.000001f }, // expected: 1 / sqrt(2) + { 1.32460909f, 0.785398163f, 0.000001f }, // expected: pi / 4 + { 1.54308063f, 1, 0.00001f }, + { 1.70710014f, 1.12837917f, 0.00001f }, // expected: 2 / sqrt(pi) + { 2.17818356f, 1.41421356f, 0.00001f }, // expected: sqrt(2) + { 2.23418810f, 1.44269504f, 0.00001f }, // expected: log2(e) + { 2.50917848f, 1.57079633f, 0.00001f }, // expected: pi / 2 + { 5.05f, 2.30258509f, 0.00001f }, // expected: ln(10) + { 7.61012514f, 2.71828183f, 0.00001f }, // expected: e + { 11.5919533f, 3.14159265f, 0.00001f }, // expected: pi + { INFINITY, INFINITY, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + + validate_isnan(-tests[i].value); + } + + validate_isnan( NAN); + validate_isnan( 0); + validate_isnan(-INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/acoshf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/acoshf/test1/testinfo.dat new file mode 100644 index 000000000000..25b5753958c6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acoshf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = acoshf +Name = Positive Test for acoshf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to acoshf() a series of values, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/asin/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asin/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/asin/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/asin/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/asin/test1/test1.c b/src/pal/tests/palsuite/c_runtime/asin/test1/test1.c index e0ac09efd0d6..76070973ed24 100644 --- a/src/pal/tests/palsuite/c_runtime/asin/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/asin/test1/test1.c @@ -7,131 +7,123 @@ ** ** Source: test1.c ** -** Purpose: Test to ensure that asin returns correct values. +** Purpose: Test to ensure that asin return the correct values ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** _finite -** - ** **===========================================================================*/ #include - -#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; /** - * main - * - * executable entry point + * validate + * + * test validation function */ -INT __cdecl main(INT argc, CHAR **argv) +void __cdecl validate(double value, double expected, double variance) { - double pi = 3.1415926535; - int i; + double result = asin(value); - struct test tests[] = - { - /* Value test result */ - { 1, pi/2.0 }, - { 0.9, 1.119769514999 }, - { 0.8, 0.927295218002 }, - { 0.7, 0.775397496611 }, - { 0.6, 0.643501108793 }, - { 0.5, 0.523598775598 }, - { 0.4, 0.411516846067 }, - { 0.3, 0.304692654015 }, - { 0.2, 0.201357920790 }, - { 0.1, 0.100167421162 }, - { 0, 0 }, - { -0.1, -0.100167421162 }, - { -0.2, -0.201357920790 }, - { -0.3, -0.304692654015 }, - { -0.4, -0.411516846067 }, - { -0.5, -0.523598775598 }, - { -0.6, -0.643501108793 }, - { -0.7, -0.775397496611 }, - { -0.8, -0.927295218002 }, - { -0.9, -1.119769514999 }, - { -1, -(pi/2.0) } - }; - - double outofrange[] = - { - -864278.51, -1000.2, -2, 2, 10, 100, 1234567.8, 1.7e308 - }; - + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if ((delta != 0) && (delta >= variance)) { - return (FAIL); + Fail("asin(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); } +} - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = asin(value); + + if (!isnan(result)) { - double result; - double testDelta; + Fail("asin(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} - result = asin( tests[i].value ); +/** + * validate + * + * test validation function for values returning +INF + */ +void __cdecl validate_isinf_positive(double value) +{ + double result = asin(value); - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "asin(%g) returned %20.10f" - " when it should have returned %20.10f", - tests[i].value, - result, - tests[i].result ); - } + if (result != INFINITY) + { + Fail("asin(%g) returned %20.17g when it should have returned %20.17g", + value, result, INFINITY); } +} - for( i = 0; i < sizeof(outofrange) / sizeof(double); i++) +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = { - double result; + /* value expected variance */ + { 0, 0, 0.000000000000001 }, + { 0.31296179620778659, 0.31830988618379067, 0.000000000000001 }, // expected: 1 / pi + { 0.41078129050290870, 0.42331082513074800, 0.000000000000001 }, // expected: pi - e + { 0.42077048331375735, 0.43429448190325183, 0.000000000000001 }, // expected: log10(e) + { 0.59448076852482208, 0.63661977236758134, 0.000000000000001 }, // expected: 2 / pi + { 0.63896127631363480, 0.69314718055994531, 0.000000000000001 }, // expected: ln(2) + { 0.64963693908006244, 0.70710678118654752, 0.000000000000001 }, // expected: 1 / sqrt(2) + { 0.70710678118654752, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4, value: 1 / sqrt(2) + { 0.74398033695749319, 0.83900756059574755, 0.000000000000001 }, // expected: pi - ln(10) + { 0.84147098480789651, 1, 0.00000000000001 }, + { 0.90371945743584630, 1.1283791670955126, 0.00000000000001 }, // expected: 2 / sqrt(pi) v + { 0.98776594599273553, 1.4142135623730950, 0.00000000000001 }, // expected: sqrt(2) + { 0.99180624439366372, 1.4426950408889634, 0.00000000000001 }, // expected: log2(e) + { 1, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 + }; - result = asin( outofrange[i] ); + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } - /* The test is valid when the function returns an infinite result */ - if( _finite( result ) ) - { - Fail( "asin(%g) returned %20.10f" - " when it should have returned -1.#IND00000000", - outofrange[i], - result ); - } + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); } + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); + PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/asin/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/asin/test1/testinfo.dat index 9e6f0fd1d0d0..8c7e0a6206fb 100644 --- a/src/pal/tests/palsuite/c_runtime/asin/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/asin/test1/testinfo.dat @@ -12,6 +12,3 @@ Description = Passes a series of values to the asin() function, = checking each for the expected result. Also checks = for proper handling of out-of-range values. - - - diff --git a/src/pal/tests/palsuite/c_runtime/asinf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asinf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/asinf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asinf/test1/CMakeLists.txt new file mode 100644 index 000000000000..b167bd871505 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_asinf_test1 + ${SOURCES} +) + +add_dependencies(paltest_asinf_test1 coreclrpal) + +target_link_libraries(paltest_asinf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/asinf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/asinf/test1/test1.c new file mode 100644 index 000000000000..ba858a3d328b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinf/test1/test1.c @@ -0,0 +1,113 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that asinf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = asinf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("asinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = asinf(value); + + if (!isnan(result)) + { + Fail("asinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000001f }, + { 0.312961796f, 0.318309886f, 0.000001f }, // expected: 1 / pi + { 0.410781291f, 0.423310825f, 0.000001f }, // expected: pi - e + { 0.420770483f, 0.434294482f, 0.000001f }, // expected: log10(e) + { 0.594480769f, 0.636619772f, 0.000001f }, // expected: 2 / pi + { 0.638961276f, 0.693147181f, 0.000001f }, // expected: ln(2) + { 0.649636939f, 0.707106781f, 0.000001f }, // expected: 1 / sqrt(2) + { 0.707106781f, 0.785398163f, 0.000001f }, // expected: pi / 4, value: 1 / sqrt(2) + { 0.743980337f, 0.839007561f, 0.000001f }, // expected: pi - ln(10) + { 0.841470985f, 1, 0.00001f }, + { 0.903719457f, 1.12837917f, 0.00001f }, // expected: 2 / sqrt(pi) + { 0.987765946f, 1.41421356f, 0.00001f }, // expected: sqrt(2) + { 0.991806244f, 1.44269504f, 0.00001f }, // expected: log2(e) + { 1, 1.57079633f, 0.00001f }, // expected: pi / 2 + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/asinf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/asinf/test1/testinfo.dat new file mode 100644 index 000000000000..f784a2bcc698 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = asinf +Name = Positive Test for asinf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the asinf() function, += checking each for the expfected result. Also checks += for proper handling of out-of-range values. diff --git a/src/pal/tests/palsuite/c_runtime/asinh/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asinh/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinh/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/asinh/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asinh/test1/CMakeLists.txt new file mode 100644 index 000000000000..2e9962bdc6bc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinh/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_asinh_test1 + ${SOURCES} +) + +add_dependencies(paltest_asinh_test1 coreclrpal) + +target_link_libraries(paltest_asinh_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/asinh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/asinh/test1/test1.c new file mode 100644 index 000000000000..65e468536e4a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinh/test1/test1.c @@ -0,0 +1,113 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that asinh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = asinh(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("asinh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = asinh(value); + + if (!isnan(result)) + { + Fail("asinh(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000000000000001 }, + { 0.32371243907207108, 0.31830988618379067, 0.000000000000001 }, // expected: 1 / pi + { 0.44807597941469025, 0.43429448190325183, 0.000000000000001 }, // expected: log10(e) + { 0.68050167815224332, 0.63661977236758134, 0.000000000000001 }, // expected: 2 / pi + { 0.75, 0.69314718055994531, 0.000000000000001 }, // expected: ln(2) + { 0.76752314512611633, 0.70710678118654752, 0.000000000000001 }, // expected: 1 / sqrt(2) + { 0.86867096148600961, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4 + { 1.1752011936438015, 1, 0.00000000000001 }, + { 1.3835428792038633, 1.1283791670955126, 0.00000000000001 }, // expected: 2 / sqrt(pi) + { 1.9350668221743567, 1.4142135623730950, 0.00000000000001 }, // expected: sqrt(2) + { 1.9978980091062796, 1.4426950408889634, 0.00000000000001 }, // expected: log2(e) + { 2.3012989023072949, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 + { 4.95, 2.3025850929940457, 0.00000000000001 }, // expected: ln(10) + { 7.5441371028169758, 2.7182818284590452, 0.00000000000001 }, // expected: e + { 11.548739357257748, 3.1415926535897932, 0.00000000000001 }, // expected: pi + { INFINITY, INFINITY, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/asinh/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/asinh/test1/testinfo.dat new file mode 100644 index 000000000000..d29f6c839fb3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinh/test1/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = asinh +Name = Positive Test for asinh +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the asinh() function, += checking each for the expected result. Also checks += for proper handling of out-of-range values. diff --git a/src/pal/tests/palsuite/c_runtime/asinhf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asinhf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinhf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/asinhf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/asinhf/test1/CMakeLists.txt new file mode 100644 index 000000000000..d49c2005ffca --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinhf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_asinhf_test1 + ${SOURCES} +) + +add_dependencies(paltest_asinhf_test1 coreclrpal) + +target_link_libraries(paltest_asinhf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/asinhf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/asinhf/test1/test1.c new file mode 100644 index 000000000000..b34134565c50 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinhf/test1/test1.c @@ -0,0 +1,113 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that asinhf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = asinhf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("asinhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = asinhf(value); + + if (!isnan(result)) + { + Fail("asinhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000001f }, + { 0.323712439f, 0.318309886f, 0.000001f }, // expected: 1 / pi + { 0.448075979f, 0.434294482f, 0.000001f }, // expected: log10(e) + { 0.680501678f, 0.636619772f, 0.000001f }, // expected: 2 / pi + { 0.75f, 0.693147181f, 0.000001f }, // expected: ln(2) + { 0.767523145f, 0.707106781f, 0.000001f }, // expected: 1 / sqrt(2) + { 0.868670961f, 0.785398163f, 0.000001f }, // expected: pi / 4 + { 1.17520119f, 1, 0.00001f }, + { 1.38354288f, 1.12837917f, 0.00001f }, // expected: 2 / sqrt(pi) + { 1.93506682f, 1.41421356f, 0.00001f }, // expected: sqrt(2) + { 1.99789801f, 1.44269504f, 0.00001f }, // expected: log2(e) + { 2.30129890f, 1.57079633f, 0.00001f }, // expected: pi / 2 + { 4.95f, 2.30258509f, 0.00001f }, // expected: ln(10) + { 7.54413710f, 2.71828183f, 0.00001f }, // expected: e + { 11.5487394f, 3.14159265f, 0.00001f }, // expected: pi + { INFINITY, INFINITY, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/asinhf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/asinhf/test1/testinfo.dat new file mode 100644 index 000000000000..91443a815de6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinhf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = asinhf +Name = Positive Test for asinhf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the asinhf() function, += checking each for the expfected result. Also checks += for proper handling of out-of-range values. diff --git a/src/pal/tests/palsuite/c_runtime/atan/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atan/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/atan/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/atan/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/atan/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atan/test1/test1.c index 5feab4824d7f..a6a835aee1d8 100644 --- a/src/pal/tests/palsuite/c_runtime/atan/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/atan/test1/test1.c @@ -7,110 +7,105 @@ ** ** Source: test1.c ** -** Purpose: Test to ensure that atan returns correct values. +** Purpose: Test to ensure that atan return the correct values ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** - ** **===========================================================================*/ #include -#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = atan(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("atan(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = atan(value); + + if (!isnan(result)) + { + Fail("atan(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + /** * main * * executable entry point */ -INT __cdecl main(INT argc, CHAR **argv) +int __cdecl main(int argc, char **argv) { - double pi = 3.1415926535; - int i; - struct test tests[] = { - /* Value test result */ - { -1.7976931348623158e+307, -(pi/2) }, - { -25928.789941099276, -1.570757759627 }, - { -10162.054261909849, -1.570697921495 }, - { -7742.279976805932, -1.570667165876 }, - { -4027.241187780389, -1.570548017858 }, - { -2020.329477828303, -1.570301358064 }, - { -928.811975463118, -1.569719683039 }, - { -0.993835261086, -0.782306273415 }, - { -0.936490981780, -0.752613986257 }, - { -0.884395886105, -0.724126849580 }, - { -0.728537858211, -0.629623252584 }, - { -0.571733756523, -0.519376146611 }, - { -0.370342112491, -0.354680802574 }, - { -0.264778588214, -0.258838835750 }, - { -0.199255348369, -0.196679446239 }, - { -0.077700125126, -0.077544322548 }, - { -0.036713766900, -0.036697284724 }, - { 0, 0}, - { 0.284035767693, 0.276747134475 }, - { 0.329264198737, 0.318083873607 }, - { 0.332560197760, 0.321054571066 }, - { 0.338206122013, 0.326129634676 }, - { 0.421887874996, 0.399231699263 }, - { 0.645222327342, 0.573009239835 }, - { 0.648396252327, 0.575246979388 }, - { 0.721427045503, 0.624962252188 }, - { 0.723685415204, 0.626445984185 }, - { 0.747856074709, 0.642127583998 }, - { 401.853083895383, 1.568307860298 }, - { 1579.672322763756, 1.570163284200 }, - { 2540.318308053835, 1.570402675359 }, - { 6105.661946470535, 1.570632544391 }, - { 10221.297708059939, 1.570698491860 }, - { 17155.000305185094, 1.570738034753 }, - { 20600.197424237798, 1.570747783571 }, - { 1.7976931348623158e+308, pi/2 } + /* value expected variance */ + { 0, 0, 0.000000000000001 }, + { 0.32951473309607836, 0.31830988618379067, 0.000000000000001 }, // expected: 1 / pi + { 0.45054953406980750, 0.42331082513074800, 0.000000000000001 }, // expected: pi - e + { 0.46382906716062964, 0.43429448190325183, 0.000000000000001 }, // expected: log10(e) + { 0.73930295048660405, 0.63661977236758134, 0.000000000000001 }, // expected: 2 / pi + { 0.83064087786078395, 0.69314718055994531, 0.000000000000001 }, // expected: ln(2) + { 0.85451043200960189, 0.70710678118654752, 0.000000000000001 }, // expected: 1 / sqrt(2) + { 1, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4 + { 1.1134071468135374, 0.83900756059574755, 0.000000000000001 }, // expected: pi - ln(10) + { 1.5574077246549022, 1, 0.00000000000001 }, + { 2.1108768356626451, 1.1283791670955126, 0.00000000000001 }, // expected: 2 / sqrt(pi) + { 6.3341191670421916, 1.4142135623730950, 0.00000000000001 }, // expected: sqrt(2) + { 7.7635756709721848, 1.4426950408889634, 0.00000000000001 }, // expected: log2(e) + { INFINITY, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 }; - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return (FAIL); + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - double testDelta; - - result = atan( tests[i].value ); - - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "atan(%g) returned %20.10f" - " when it should have returned %20.10f", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); } + validate_isnan(NAN); + PAL_Terminate(); return PASS; } diff --git a/src/pal/tests/palsuite/c_runtime/atan/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/atan/test1/testinfo.dat index 685b85888cb6..3a4bec0687c8 100644 --- a/src/pal/tests/palsuite/c_runtime/atan/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/atan/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes a series of values to the atan() function, = checking each for the expected result. - - - diff --git a/src/pal/tests/palsuite/c_runtime/atan2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atan2/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/atan2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/atan2/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.c index 4b39addd42b3..120ef8227c1d 100644 --- a/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/atan2/test1/test1.c @@ -16,73 +16,116 @@ #include -#define DELTA 0.0000001 //Error acceptance level to the 7th decimal - - struct test { - double x; - double y; - double result; // expected result + double y; /* second component of the value to test the function with */ + double x; /* first component of the value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; - -void DoTest(double x, double y, double expected) +/** + * validate + * + * test validation function + */ +void __cdecl validate(double y, double x, double expected, double variance) { - double result; - double testDelta; + double result = atan2(y, x); - result = atan2(x, y); + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); - // The test is valid when the difference between the - // result and the expectation is less than DELTA - testDelta = fabs(result - expected); - if( testDelta >= DELTA ) + if ((delta != 0) && (delta >= variance)) { - Fail( "atan2(%g, %g) returned %g when it should have returned %g", - x, y, result, expected); + Fail("atan2(%g, %g) returned %20.15g when it should have returned %20.15g", + y, x, result, expected); } } -int __cdecl main(int argc, char **argv) +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double y, double x) { - double pi = 3.1415926535; - int i; + double result = atan2(y, x); + if (!isnan(result)) + { + Fail("atan2(%g, %g) returned %20.15g when it should have returned %20.15g", + y, x, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ struct test tests[] = { - {0, 0, 0}, - {0, 1, 0}, - {0.104528463, 0.994521895, 0.104719755}, - {0.207911691, 0.978147601, 0.20943951}, - {0.309016994, 0.951056516, 0.314159265}, - {0.406736643, 0.913545458, 0.41887902}, - {0.5, 0.866025404, 0.523598776}, - {0.587785252, 0.809016994, 0.628318531}, - {0.669130606, 0.743144825, 0.733038286}, - {0.743144825, 0.669130606, 0.837758041}, - {0.809016994, 0.587785252, 0.942477796}, - {0.866025404, 0.5, 1.04719755}, - {0.913545458, 0.406736643, 1.15191731}, - {0.951056516, 0.309016994, 1.25663706}, - {0.978147601, 0.207911691, 1.36135682}, - {0.994521895, 0.104528463, 1.46607657}, - {1, 4.48965922e-011, 1.57079633}, + /* y x expected variance */ + { 0, INFINITY, 0, 0.000000000000001 }, + { 0, 0, 0, 0.000000000000001 }, + { 0.31296179620778659, 0.94976571538163866, 0.31830988618379067, 0.000000000000001 }, // expected: 1 / pi + { 0.42077048331375735, 0.90716712923909839, 0.43429448190325183, 0.000000000000001 }, // expected: log10(e) + { 0.59448076852482208, 0.80410982822879171, 0.63661977236758134, 0.000000000000001 }, // expected: 2 / pi + { 0.63896127631363480, 0.76923890136397213, 0.69314718055994531, 0.000000000000001 }, // expected: ln(2) + { 0.64963693908006244, 0.76024459707563015, 0.70710678118654752, 0.000000000000001 }, // expected: 1 / sqrt(2) + { 0.70710678118654752, 0.70710678118654752, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4, value: 1 / sqrt(2) + { 1, 1, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4 + { INFINITY, INFINITY, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4 + { 0.84147098480789651, 0.54030230586813972, 1, 0.00000000000001 }, + { 0.90371945743584630, 0.42812514788535792, 1.1283791670955126, 0.00000000000001 }, // expected: 2 / sqrt(pi) + { 0.98776594599273553, 0.15594369476537447, 1.4142135623730950, 0.00000000000001 }, // expected: sqrt(2) + { 0.99180624439366372, 0.12775121753523991, 1.4426950408889634, 0.00000000000001 }, // expected: log2(e) + { 1, 0, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 + { INFINITY, 0, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 + { INFINITY, 1, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 + { 0.74398033695749319, -0.66820151019031295, 2.3025850929940457, 0.00000000000001 }, // expected: ln(10) + { 0.41078129050290870, -0.91173391478696510, 2.7182818284590452, 0.00000000000001 }, // expected: e + { 0, -1, 3.1415926535897932, 0.00000000000001 }, // expected: pi + { 1, INFINITY, 0, 0.000000000000001 }, }; - if (PAL_Initialize(argc, argv) != 0) { - return FAIL; + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - DoTest(tests[i].x, tests[i].y, tests[i].result); - DoTest(-tests[i].x, tests[i].y, -tests[i].result); - DoTest(tests[i].x, -tests[i].y, pi - tests[i].result); - DoTest(-tests[i].x, -tests[i].y, tests[i].result - pi); + const double pi = 3.1415926535897932; + + validate( tests[i].y, tests[i].x, tests[i].expected, tests[i].variance); + validate(-tests[i].y, tests[i].x, -tests[i].expected, tests[i].variance); + validate( tests[i].y, -tests[i].x, pi - tests[i].expected, tests[i].variance); + validate(-tests[i].y, -tests[i].x, tests[i].expected - pi, tests[i].variance); } + + validate_isnan(-INFINITY, NAN); + validate_isnan( NAN, -INFINITY); + validate_isnan( NAN, INFINITY); + validate_isnan( INFINITY, NAN); + + validate_isnan( NAN, -1); + validate_isnan( NAN, -0.0); + validate_isnan( NAN, 0); + validate_isnan( NAN, 1); + + validate_isnan(-1, NAN); + validate_isnan(-0.0, NAN); + validate_isnan( 0, NAN); + validate_isnan( 1, NAN); + + validate_isnan( NAN, NAN); PAL_Terminate(); return PASS; diff --git a/src/pal/tests/palsuite/c_runtime/atan2f/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atan2f/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2f/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/atan2f/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atan2f/test1/CMakeLists.txt new file mode 100644 index 000000000000..d71a61b17b99 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2f/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_atan2f_test1 + ${SOURCES} +) + +add_dependencies(paltest_atan2f_test1 coreclrpal) + +target_link_libraries(paltest_atan2f_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/atan2f/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atan2f/test1/test1.c new file mode 100644 index 000000000000..bbbb2eff95e2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2f/test1/test1.c @@ -0,0 +1,132 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Tests that atan2f returns correct values for a subset of values. +** Tests with positive and negative values of x and y to ensure +** atan2f is returning results from the correct quadrant. +** +** +**===================================================================*/ + +#include + +struct test +{ + float y; /* second component of the value to test the function with */ + float x; /* first component of the value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float y, float x, float expected, float variance) +{ + float result = atan2f(y, x); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("atan2f(%g, %g) returned %10.9g when it should have returned %10.9g", + y, x, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float y, float x) +{ + float result = atan2f(y, x); + + if (!isnan(result)) + { + Fail("atan2f(%g, %g) returned %10.9g when it should have returned %10.9g", + y, x, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* y x expected variance */ + { 0, INFINITY, 0, 0.000001f }, + { 0, 0, 0, 0.000001f }, + { 0.312961796f, 0.949765715f, 0.318309886f, 0.000001f }, // expected: 1 / pi + { 0.420770483f, 0.907167129f, 0.434294482f, 0.000001f }, // expected: log10(e) + { 0.594480769f, 0.804109828f, 0.636619772f, 0.000001f }, // expected: 2 / pi + { 0.638961276f, 0.769238901f, 0.693147181f, 0.000001f }, // expected: ln(2) + { 0.649636939f, 0.760244597f, 0.707106781f, 0.000001f }, // expected: 1 / sqrt(2) + { 0.707106781f, 0.707106781f, 0.785398163f, 0.000001f }, // expected: pi / 4, value: 1 / sqrt(2) + { 1, 1, 0.785398163f, 0.000001f }, // expected: pi / 4 + { INFINITY, INFINITY, 0.785398163f, 0.000001f }, // expected: pi / 4 + { 0.841470985f, 0.540302306f, 1, 0.00001f }, + { 0.903719457f, 0.428125148f, 1.128379167f, 0.00001f }, // expected: 2 / sqrt(pi) + { 0.987765946f, 0.155943695f, 1.414213562f, 0.00001f }, // expected: sqrt(2) + { 0.991806244f, 0.127751218f, 1.442695041f, 0.00001f }, // expected: log2(e) + { 1, 0, 1.570796327f, 0.00001f }, // expected: pi / 2 + { INFINITY, 0, 1.570796327f, 0.00001f }, // expected: pi / 2 + { INFINITY, 1, 1.570796327f, 0.00001f }, // expected: pi / 2 + { 0.743980337f, -0.668201510f, 2.302585093f, 0.00001f }, // expected: ln(10) + { 0.410781291f, -0.911733915f, 2.718281828f, 0.00001f }, // expected: e + { 0, -1, 3.141592654f, 0.00001f }, // expected: pi + { 1, INFINITY, 0, 0.000001f }, + }; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + const float pi = 3.141592654f; + + validate( tests[i].y, tests[i].x, tests[i].expected, tests[i].variance); + validate(-tests[i].y, tests[i].x, -tests[i].expected, tests[i].variance); + validate( tests[i].y, -tests[i].x, pi - tests[i].expected, tests[i].variance); + validate(-tests[i].y, -tests[i].x, tests[i].expected - pi, tests[i].variance); + } + + validate_isnan(-INFINITY, NAN); + validate_isnan( NAN, -INFINITY); + validate_isnan( NAN, INFINITY); + validate_isnan( INFINITY, NAN); + + validate_isnan(NAN, -1); + validate_isnan(NAN, -0.0f); + validate_isnan(NAN, 0); + validate_isnan(NAN, 1); + + validate_isnan(-1, NAN); + validate_isnan(-0.0f, NAN); + validate_isnan( 0, NAN); + validate_isnan( 1, NAN); + + validate_isnan(NAN, NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/atan2f/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/atan2f/test1/testinfo.dat new file mode 100644 index 000000000000..5a4cc812b0eb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atan2f/test1/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = atan2f +Name = Test #1 for atan2f +Type = DEFAULT +EXE1 = test1 +Description +=Tests that atan2f returns correct values for a subset of values. +=Tests with positive and negative values of x and y to ensure +=atan2f is returning results from the correct quadrant. diff --git a/src/pal/tests/palsuite/c_runtime/atanf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atanf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/atanf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atanf/test1/CMakeLists.txt new file mode 100644 index 000000000000..b71b1cf40c36 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_atanf_test1 + ${SOURCES} +) + +add_dependencies(paltest_atanf_test1 coreclrpal) + +target_link_libraries(paltest_atanf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/atanf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atanf/test1/test1.c new file mode 100644 index 000000000000..d465b0906e0c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanf/test1/test1.c @@ -0,0 +1,111 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that atanf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = atanf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("atanf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = atanf(value); + + if (!isnan(result)) + { + Fail("atanf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000001f }, + { 0.329514733f, 0.318309886f, 0.000001f }, // expected: 1 / pi + { 0.450549534f, 0.423310825f, 0.000001f }, // expected: pi - e + { 0.463829067f, 0.434294482f, 0.000001f }, // expected: log10(e) + { 0.739302950f, 0.636619772f, 0.000001f }, // expected: 2 / pi + { 0.830640878f, 0.693147181f, 0.000001f }, // expected: ln(2) + { 0.854510432f, 0.707106781f, 0.000001f }, // expected: 1 / sqrt(2) + { 1, 0.785398163f, 0.000001f }, // expected: pi / 4 + { 1.11340715f, 0.839007561f, 0.000001f }, // expected: pi - ln(10) + { 1.55740772f, 1, 0.00001f }, + { 2.11087684f, 1.12837917f, 0.00001f }, // expected: 2 / sqrt(pi) + { 6.33411917f, 1.41421356f, 0.00001f }, // expected: sqrt(2) + { 7.76357567f, 1.44269504f, 0.00001f }, // expected: log2(e) + { INFINITY, 1.57079633f, 0.00001f }, // expected: pi / 2 + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/atanf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/atanf/test1/testinfo.dat new file mode 100644 index 000000000000..e5438c3c865f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = atanf +Name = Positive Test for atanf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the atanf() function, += checking each for the expfected result. diff --git a/src/pal/tests/palsuite/c_runtime/atanh/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atanh/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanh/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/atanh/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atanh/test1/CMakeLists.txt new file mode 100644 index 000000000000..42a902c8b2dc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanh/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_atanh_test1 + ${SOURCES} +) + +add_dependencies(paltest_atanh_test1 coreclrpal) + +target_link_libraries(paltest_atanh_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/atanh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atanh/test1/test1.c new file mode 100644 index 000000000000..9c9b8cb8f7ad --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanh/test1/test1.c @@ -0,0 +1,115 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that atanh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = atanh(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("atanh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = atanh(value); + + if (!isnan(result)) + { + Fail("atanh(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000000000000001 }, + { 0.30797791269089433, 0.31830988618379067, 0.000000000000001 }, // expected: 1 / pi + { 0.40890401183401433, 0.43429448190325183, 0.000000000000001 }, // expected: log10(e) + { 0.56259360033158334, 0.63661977236758134, 0.000000000000001 }, // expected: 2 / pi + { 0.6, 0.69314718055994531, 0.000000000000001 }, // expected: ln(2) + { 0.60885936501391381, 0.70710678118654752, 0.000000000000001 }, // expected: 1 / sqrt(2) + { 0.65579420263267244, 0.78539816339744831, 0.000000000000001 }, // expected: pi / 4 + { 0.76159415595576489, 1, 0.00000000000001 }, + { 0.81046380599898809, 1.1283791670955126, 0.00000000000001 }, // expected: 2 / sqrt(pi) + { 0.88838556158566054, 1.4142135623730950, 0.00000000000001 }, // expected: sqrt(2) + { 0.89423894585503855, 1.4426950408889634, 0.00000000000001 }, // expected: log2(e) + { 0.91715233566727435, 1.5707963267948966, 0.00000000000001 }, // expected: pi / 2 + { 0.98019801980198020, 2.3025850929940457, 0.00000000000001 }, // expected: ln(10) + { 0.99132891580059984, 2.7182818284590452, 0.00000000000001 }, // expected: e + { 0.99627207622074994, 3.1415926535897932, 0.00000000000001 }, // expected: pi + { 1, INFINITY, 0 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/atanh/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/atanh/test1/testinfo.dat new file mode 100644 index 000000000000..1df0c68877d3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanh/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = atanh +Name = Positive Test for atanh +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the atanh() function, += checking each for the expected result. diff --git a/src/pal/tests/palsuite/c_runtime/atanhf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atanhf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanhf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/atanhf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/atanhf/test1/CMakeLists.txt new file mode 100644 index 000000000000..b068effbcf4b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanhf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_atanhf_test1 + ${SOURCES} +) + +add_dependencies(paltest_atanhf_test1 coreclrpal) + +target_link_libraries(paltest_atanhf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/atanhf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/atanhf/test1/test1.c new file mode 100644 index 000000000000..03477967fe08 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanhf/test1/test1.c @@ -0,0 +1,115 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that atanhf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = atanhf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("atanhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = atanhf(value); + + if (!isnan(result)) + { + Fail("atanhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000001f }, + { 0.307977913f, 0.318309886f, 0.000001f }, // expected: 1 / pi + { 0.408904011f, 0.434294482f, 0.000001f }, // expected: log10(e) + { 0.562593600f, 0.636619772f, 0.000001f }, // expected: 2 / pi + { 0.6f, 0.693147181f, 0.000001f }, // expected: ln(2) + { 0.608859365f, 0.707106781f, 0.000001f }, // expected: 1 / sqrt(2) + { 0.655794203f, 0.785398163f, 0.000001f }, // expected: pi / 4 + { 0.761594156f, 1, 0.00001f }, + { 0.810463806f, 1.12837917f, 0.00001f }, // expected: 2 / sqrt(pi) + { 0.888385562f, 1.41421356f, 0.00001f }, // expected: sqrt(2) + { 0.894238946f, 1.44269504f, 0.00001f }, // expected: log2(e) + { 0.917152336f, 1.57079633f, 0.00001f }, // expected: pi / 2 + { 0.980198020f, 2.30258509f, 0.00001f }, // expected: ln(10) + { 0.991328916f, 2.71828183f, 0.00001f }, // expected: e + { 0.996272076f, 3.14159265f, 0.00001f }, // expected: pi + { 1, INFINITY, 0 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/atanhf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/atanhf/test1/testinfo.dat new file mode 100644 index 000000000000..69f6bf9f4af9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanhf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = atanhf +Name = Positive Test for atanhf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the atanhf() function, += checking each for the expfected result. diff --git a/src/pal/tests/palsuite/c_runtime/ceil/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/ceil/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/ceil/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/ceil/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.c b/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.c index 946fec162719..a24eb675a624 100644 --- a/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/ceil/test1/test1.c @@ -12,97 +12,104 @@ ** negative infinity. Makes sure that calling ceil on NaN returns ** NaN ** -** **==========================================================================*/ #include -typedef struct -{ - double value; - double ceilVal; -} testCase; - -typedef struct +/** + * Helper test structure + */ +struct test { - INT64 value; - INT64 ceilVal; -} extremeCase; - -#define INT64_TO_DOUBLE(a) (*(double*)&a) - -int __cdecl main(int argc, char *argv[]) + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) { - INT64 NaN = I64(0x7ff8000000000000); - double value; - double ceilVal; - double ret; - int i; - - testCase testCases[] = - { - {2.8, 3}, - {-2.8, -2}, - {5.5, 6}, - {-5.5, -5}, - {3, 3}, - {-3, -3}, - {0, 0}, - }; - extremeCase extremeCases[] = - { - /* Positive Infinity */ - {I64(0x7ff0000000000000), I64(0x7ff0000000000000)}, - /* Negative Infinitey */ - {I64(0xfff0000000000000), I64(0xfff0000000000000)}, - /* Smallest possible +value */ - {I64(0x0000000000000001), I64(0x3FF0000000000000)}, - /* Smallest possible -value */ - {I64(0x8000000000000001), I64(0x8000000000000000)}, - }; - + double result = ceil(value); /* - * Initialize the PAL and return FAIL if this fails + * The test is valid when the difference between the + * result and the expectation is less than DELTA */ - if (0 != (PAL_Initialize(argc, argv))) + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) { - return FAIL; + Fail("ceil(%g) returned %20.15g when it should have returned %20.15g", + value, result, expected); } +} +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = ceil(value); - for (i=0; i + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = ceilf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("ceilf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = ceilf(value); + + if (!isnan(result)) + { + Fail("ceilf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char *argv[]) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.318309886f, 1, 0.00001f }, // value: 1 / pi + { 0.434294482f, 1, 0.00001f }, // value: log10(e) + { 0.636619772f, 1, 0.00001f }, // value: 2 / pi + { 0.693147181f, 1, 0.00001f }, // value: ln(2) + { 0.707106781f, 1, 0.00001f }, // value: 1 / sqrt(2) + { 0.785398163f, 1, 0.00001f }, // value: pi / 4 + { 1.12837917f, 2, 0.00001f }, // value: 2 / sqrt(pi) + { 1.41421356f, 2, 0.00001f }, // value: sqrt(2) + { 1.44269504f, 2, 0.00001f }, // value: log2(e) + { 1.57079633f, 2, 0.00001f }, // value: pi / 2 + { 2.30258509f, 3, 0.00001f }, // value: ln(10) + { 2.71828183f, 3, 0.00001f }, // value: e + { 3.14159265f, 4, 0.00001f }, // value: pi + { INFINITY, INFINITY, 0 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate( 0, 0, 0.000001f); + validate(-0.0f, 0, 0.000001f); + + validate( 1, 1, 0.00001f); + validate(-1.0, -1, 0.00001f); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, 1 - tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/ceilf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/ceilf/test1/testinfo.dat new file mode 100644 index 000000000000..9ce69ba58e1b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/ceilf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = ceilf +Name = Test #1 for ceilf +TYPE = DEFAULT +EXE1 = test1 +Description +=Tests ceilf with simple positive and negative values. Also tests +=extreme cases like extremely small values and positive and negative +=infinity. Makes sure that calling ceilf on NaN returns NaN diff --git a/src/pal/tests/palsuite/c_runtime/cos/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cos/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/cos/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/cos/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/cos/test1/test1.c b/src/pal/tests/palsuite/c_runtime/cos/test1/test1.c index fbd6e064e82b..5736b3e1dc4a 100644 --- a/src/pal/tests/palsuite/c_runtime/cos/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/cos/test1/test1.c @@ -13,79 +13,102 @@ ** PAL_Terminate ** Fail ** fabs -** - ** **===========================================================================*/ #include -#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = cos(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("cos(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = cos(value); + + if (!isnan(result)) + { + Fail("cos(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + /** * main * * executable entry point */ -INT __cdecl main(INT argc, CHAR **argv) +int __cdecl main(int argc, char **argv) { - double pi = 3.1415926535; - int i; - struct test tests[] = { - /* Value test result */ - { 0, 1 }, - { pi/2.0, 0 }, - { pi, -1 }, - { (3.0*pi) / 2.0, 0 }, - { 2.0 * pi, 1 }, - { 5.0*pi/2.0, 0 }, - { 3.0*pi, -1 }, - { (7.0*pi) / 2.0, 0 }, - { 4.0 * pi, 1 }, - { 1.7e-12, 1 }, - { 1.7e+12, 0.1745850 } + /* value expected variance */ + { 0, 1, 0.00000000000001 }, + { 0.31830988618379067, 0.94976571538163866, 0.000000000000001 }, // value: 1 / pi + { 0.43429448190325183, 0.90716712923909839, 0.000000000000001 }, // value: log10(e) + { 0.63661977236758134, 0.80410982822879171, 0.000000000000001 }, // value: 2 / pi + { 0.69314718055994531, 0.76923890136397213, 0.000000000000001 }, // value: ln(2) + { 0.70710678118654752, 0.76024459707563015, 0.000000000000001 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.70710678118654752, 0.000000000000001 }, // value: pi / 4, expected: 1 / sqrt(2) + { 1, 0.54030230586813972, 0.000000000000001 }, + { 1.1283791670955126, 0.42812514788535792, 0.000000000000001 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 0.15594369476537447, 0.000000000000001 }, // value: sqrt(2) + { 1.4426950408889634, 0.12775121753523991, 0.000000000000001 }, // value: log2(e) + { 1.5707963267948966, 0, 0.000000000000001 }, // value: pi / 2 + { 2.3025850929940457, -0.66820151019031295, 0.000000000000001 }, // value: ln(10) + { 2.7182818284590452, -0.91173391478696510, 0.000000000000001 }, // value: e + { 3.1415926535897932, -1, 0.00000000000001 }, // value: pi }; - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return (FAIL); + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - double testDelta; - - result = cos( tests[i].value ); - - /* The test is valid when the difference between the */ - /* result and the expectation is less than DELTA */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "cos(%g) returned %20.10g" - " when it should have returned %20.10g", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); PAL_Terminate(); return PASS; } - - diff --git a/src/pal/tests/palsuite/c_runtime/cos/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/cos/test1/testinfo.dat index 2611c7b6d6f0..1e8804b5efea 100644 --- a/src/pal/tests/palsuite/c_runtime/cos/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/cos/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to cos() a series of angle value, checking that = each one return the correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/cosf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cosf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cosf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/exp/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cosf/test1/CMakeLists.txt similarity index 50% rename from src/pal/tests/palsuite/c_runtime/exp/test2/CMakeLists.txt rename to src/pal/tests/palsuite/c_runtime/cosf/test1/CMakeLists.txt index 5e9d291674a0..b3a18ea271b6 100644 --- a/src/pal/tests/palsuite/c_runtime/exp/test2/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/cosf/test1/CMakeLists.txt @@ -3,16 +3,16 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test2.c + test1.c ) -add_executable(paltest_exp_test2 +add_executable(paltest_cosf_test1 ${SOURCES} ) -add_dependencies(paltest_exp_test2 coreclrpal) +add_dependencies(paltest_cosf_test1 coreclrpal) -target_link_libraries(paltest_exp_test2 +target_link_libraries(paltest_cosf_test1 pthread m coreclrpal diff --git a/src/pal/tests/palsuite/c_runtime/cosf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/cosf/test1/test1.c new file mode 100644 index 000000000000..570bc17aeb37 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cosf/test1/test1.c @@ -0,0 +1,114 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that cosf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = cosf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("cosf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = cosf(value); + + if (!isnan(result)) + { + Fail("cosf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 1, 0.00001f }, + { 0.318309886f, 0.949765715f, 0.000001f }, // value: 1 / pi + { 0.434294482f, 0.907167129f, 0.000001f }, // value: log10(e) + { 0.636619772f, 0.804109828f, 0.000001f }, // value: 2 / pi + { 0.693147181f, 0.769238901f, 0.000001f }, // value: ln(2) + { 0.707106781f, 0.760244597f, 0.000001f }, // value: 1 / sqrt(2) + { 0.785398163f, 0.707106781f, 0.000001f }, // value: pi / 4, value: 1 / sqrt(2) + { 1, 0.540302306f, 0.000001f }, + { 1.12837917f, 0.428125148f, 0.000001f }, // value: 2 / sqrt(pi) + { 1.41421356f, 0.155943695f, 0.000001f }, // value: sqrt(2) + { 1.44269504f, 0.127751218f, 0.000001f }, // value: log2(e) + { 1.57079633f, 0, 0.000001f }, // value: pi / 2 + { 2.30258509f, -0.668201510f, 0.000001f }, // value: ln(10) + { 2.71828183f, -0.911733915f, 0.000001f }, // value: e + { 3.14159265f, -1, 0.00001f }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/cosf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/cosf/test1/testinfo.dat new file mode 100644 index 000000000000..51ff36966128 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cosf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = cosf +Name = Positive Test for cosf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to cosf() a series of angle value, checking that += each one return the correct value. diff --git a/src/pal/tests/palsuite/c_runtime/cosh/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cosh/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/cosh/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/cosh/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.c index 650d19e94a6e..dd6463814bc7 100644 --- a/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/cosh/test1/test1.c @@ -11,93 +11,103 @@ ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** - ** **===========================================================================*/ #include -#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = cosh(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("cosh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NAN + */ +void __cdecl validate_isnan(double value) +{ + double result = cosh(value); + + if (!isnan(result)) + { + Fail("cosh(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + /** * main * * executable entry point */ -INT __cdecl main(INT argc, CHAR **argv) +int __cdecl main(int argc, char **argv) { - double pi = 3.1415926535; - int i; - struct test tests[] = { - /* Value test result */ - { 0, 1 }, - { pi/2.0, 2.5091785 }, - { pi, 11.5919533 }, - { (3.0*pi) / 2.0, 55.6633809 }, - { 2.0 * pi, 267.7467614 }, - { 5.0*pi/2.0, 1287.9854421 }, - { 3.0*pi, 6195.8239426 }, - { (7.0*pi) / 2.0, 29804.8707455 }, - { 4.0 * pi, 143375.6565186 } + /* value expected variance */ + { 0, 1, 0.00000000000001 }, + { 0.31830988618379067, 1.0510897883672876, 0.00000000000001 }, // value: 1 / pi + { 0.43429448190325183, 1.0957974645564909, 0.00000000000001 }, // value: log10(e) + { 0.63661977236758134, 1.2095794864199787, 0.00000000000001 }, // value: 2 / pi + { 0.69314718055994531, 1.25, 0.00000000000001 }, // value: ln(2) + { 0.70710678118654752, 1.2605918365213561, 0.00000000000001 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 1.3246090892520058, 0.00000000000001 }, // value: pi / 4 + { 1, 1.5430806348152438, 0.00000000000001 }, + { 1.1283791670955126, 1.7071001431069344, 0.00000000000001 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 2.1781835566085709, 0.00000000000001 }, // value: sqrt(2) + { 1.4426950408889634, 2.2341880974508023, 0.00000000000001 }, // value: log2(e) + { 1.5707963267948966, 2.5091784786580568, 0.00000000000001 }, // value: pi / 2 + { 2.3025850929940457, 5.05, 0.00000000000001 }, // value: ln(10) + { 2.7182818284590452, 7.6101251386622884, 0.00000000000001 }, // value: e + { 3.1415926535897932, 11.591953275521521, 0.0000000000001 }, // value: pi + { INFINITY, INFINITY, 0 }, }; - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return (FAIL); + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - double testDelta; - - - result = cosh( tests[i].value ); - - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "cosh(%g) returned %g" - " when it should have returned %g", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); } + + validate_isnan(NAN); PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/cosh/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/cosh/test1/testinfo.dat index 00df2a9741ad..172ce5af5595 100644 --- a/src/pal/tests/palsuite/c_runtime/cosh/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/cosh/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to cosh() a series of angle value, checking that = each one return to correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/coshf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/coshf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/coshf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/coshf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/coshf/test1/CMakeLists.txt new file mode 100644 index 000000000000..92fcfdea6d2c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/coshf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_coshf_test1 + ${SOURCES} +) + +add_dependencies(paltest_coshf_test1 coreclrpal) + +target_link_libraries(paltest_coshf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/coshf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/coshf/test1/test1.c new file mode 100644 index 000000000000..06d2e53e0f9b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/coshf/test1/test1.c @@ -0,0 +1,113 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that coshf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = coshf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("coshf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = coshf(value); + + if (!isnan(result)) + { + Fail("coshf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 1, 0.00001f }, + { 0.318309886f, 1.05108979f, 0.00001f }, // value: 1 / pi + { 0.434294482f, 1.09579746f, 0.00001f }, // value: log10(e) + { 0.636619772f, 1.20957949f, 0.00001f }, // value: 2 / pi + { 0.693147181f, 1.25f, 0.00001f }, // value: ln(2) + { 0.707106781f, 1.26059184f, 0.00001f }, // value: 1 / sqrt(2) + { 0.785398163f, 1.32460909f, 0.00001f }, // value: pi / 4 + { 1, 1.54308063f, 0.00001f }, + { 1.12837917f, 1.70710014f, 0.00001f }, // value: 2 / sqrt(pi) + { 1.41421356f, 2.17818356f, 0.00001f }, // value: sqrt(2) + { 1.44269504f, 2.23418810f, 0.00001f }, // value: log2(e) + { 1.57079633f, 2.50917848f, 0.00001f }, // value: pi / 2 + { 2.30258509f, 5.05f, 0.00001f }, // value: ln(10) + { 2.71828183f, 7.61012514f, 0.00001f }, // value: e + { 3.14159265f, 11.5919533f, 0.0001f }, // value: pi + { INFINITY, INFINITY, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/coshf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/coshf/test1/testinfo.dat new file mode 100644 index 000000000000..2c73d67e106b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/coshf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = coshf +Name = Positive Test for coshf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to coshf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/exp/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/exp/CMakeLists.txt index 1962ade35859..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/exp/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/exp/CMakeLists.txt @@ -1,6 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) -add_subdirectory(test2) -add_subdirectory(test3) - diff --git a/src/pal/tests/palsuite/c_runtime/exp/test1/test1.c b/src/pal/tests/palsuite/c_runtime/exp/test1/test1.c index 177274afb01f..1f1601b9101a 100644 --- a/src/pal/tests/palsuite/c_runtime/exp/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/exp/test1/test1.c @@ -14,51 +14,109 @@ #include +/** + * Helper test structure + */ struct test { - double value; - double result; - double delta; + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = exp(value); -int __cdecl main(int argc, char **argv) -{ - double value; - double testDelta; - int i; + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); - struct test tests[] = + if ((delta != 0) && (delta >= variance)) + { + Fail("exp(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = exp(value); + + if (!isnan(result)) { - {0, 1, 1e-7}, - {0.5, 1.64872127, 1e-7}, - {-0.5, 0.60653066, 1e-7}, - {1, 2.71828183, 1e-7}, - {-1, 0.367879441, 1e-7}, - {10, 2.202646579481e+004, 1e-4}, - {-10, 4.53999298e-005, 1e-13}, + Fail("exp(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} - {600, 3.7730203009299397e+260, 1e+252}, - {-600, 2.6503965530043108e-261, 1e-269} +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { -INFINITY, 0, 1e-15 }, // value: -(inf) expected: 0 + { -3.1415926535897932, 0.043213918263772250, 1e-16 }, // value: -(pi) + { -2.7182818284590452, 0.065988035845312537, 1e-16 }, // value: -(e) + { -2.3025850929940457, 0.1, 1e-15 }, // value: -(ln(10)) expected: 1 / 10 + { -1.5707963267948966, 0.20787957635076191, 1e-15 }, // value: -(pi / 2) + { -1.4426950408889634, 0.23629008834452270, 1e-15 }, // value: -(log2(e)) + { -1.4142135623730950, 0.24311673443421421, 1e-15 }, // value: -(sqrt(2)) + { -1.1283791670955126, 0.32355726390307110, 1e-15 }, // value: -(2 / sqrt(pi)) + { -1, 0.36787944117144232, 1e-15 }, // value: -(1) + { -0.78539816339744831, 0.45593812776599624, 1e-15 }, // value: -(pi / 4) + { -0.70710678118654752, 0.49306869139523979, 1e-15 }, // value: -(1 / sqrt(2)) + { -0.69314718055994531, 0.5, 1e-15 }, // value: -(ln(2)) expected: 1 / 2 + { -0.63661977236758134, 0.52907780826773535, 1e-15 }, // value: -(2 / pi) + { -0.43429448190325183, 0.64772148514180065, 1e-15 }, // value: -(log10(e)) + { -0.31830988618379067, 0.72737734929521647, 1e-15 }, // value: -(1 / pi) + { 0, 1, 1e-14 }, // value: 0 expected: 1 + { 0.31830988618379067, 1.3748022274393586, 1e-14 }, // value: 1 / pi + { 0.43429448190325183, 1.5438734439711811, 1e-14 }, // value: log10(e) + { 0.63661977236758134, 1.8900811645722220, 1e-14 }, // value: 2 / pi + { 0.69314718055994531, 2, 1e-14 }, // value: ln(2) expected: 2 + { 0.70710678118654752, 2.0281149816474725, 1e-14 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 2.1932800507380155, 1e-14 }, // value: pi / 4 + { 1, 2.7182818284590452, 1e-14 }, // expected: e + { 1.1283791670955126, 3.0906430223107976, 1e-14 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 4.1132503787829275, 1e-14 }, // value: sqrt(2) + { 1.4426950408889634, 4.2320861065570819, 1e-14 }, // value: log2(e) + { 1.5707963267948966, 4.8104773809653517, 1e-14 }, // value: pi / 2 + { 2.3025850929940457, 10, 1e-13 }, // value: ln(10) expected: 10 + { 2.7182818284590452, 15.154262241479264, 1e-13 }, // value: e + { 3.1415926535897932, 23.140692632779269, 1e-13 }, // value: pi + { INFINITY, INFINITY, 0 }, // value: inf expected: inf }; if (PAL_Initialize(argc, argv) != 0) { - return FAIL; + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - value = exp(tests[i].value); - - testDelta = fabs(value - tests[i].result); - if( testDelta >= tests[i].delta ) - { - Fail("exp(%g) returned %g when it should have returned %g\n", - tests[i].value, value, tests[i].result); - } + validate(tests[i].value, tests[i].expected, tests[i].variance); } + + validate_isnan(NAN); PAL_Terminate(); return PASS; diff --git a/src/pal/tests/palsuite/c_runtime/exp/test2/test2.c b/src/pal/tests/palsuite/c_runtime/exp/test2/test2.c deleted file mode 100644 index 10f74aa8af71..000000000000 --- a/src/pal/tests/palsuite/c_runtime/exp/test2/test2.c +++ /dev/null @@ -1,65 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*===================================================================== -** -** Source: test1.c -** -** Purpose: Tests that exp handles underflows, overflows, and NaNs -** corectly. -** -** -**===================================================================*/ - -#include - -int __cdecl main(int argc, char **argv) -{ - double zero = 0.0; - double PosInf = 1.0 / zero; - double NaN = 0.0 / zero; - // Force 'value' to be converted to a double to avoid - // using the internal precision of the FPU for comparisons. - volatile double value; - - if (PAL_Initialize(argc, argv) != 0) - { - return FAIL; - } - - /* Test overflows give PosInf */ - value = exp(800.0); - if (value != PosInf) - { - Fail( "exp(%g) returned %g when it should have returned %g\n", - 800.0, value, PosInf); - } - - value = exp(PosInf); - if (value != PosInf) - { - Fail( "exp(%g) returned %g when it should have returned %g\n", - PosInf, value, PosInf); - } - - /* Test underflows give 0 */ - value = exp(-800); - if (value != 0) - { - Fail( "exp(%g) returned %g when it should have returned %g\n", - -800.0, value, 0.0); - } - - /* Test that a NaN as input gives a NaN */ - value = exp(NaN); - if (_isnan(value) == 0) - { - Fail( "exp( NaN ) returned %g when it should have returned NaN\n", - value); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/exp/test3/test3.c b/src/pal/tests/palsuite/c_runtime/exp/test3/test3.c deleted file mode 100644 index 9236c339dc46..000000000000 --- a/src/pal/tests/palsuite/c_runtime/exp/test3/test3.c +++ /dev/null @@ -1,110 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*============================================================================= -** -** Source: test3.c -** -** Purpose: Test to ensure that exp returns correct values. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** _finite -** _isnan -** - -** -**===========================================================================*/ - -#include - -#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */ - -/** - * Helper test structure - */ -struct test -{ - double value; /* value to test the function with */ - double result; /* expected result */ -}; - -/** - * main - * - * executable entry point - */ -INT __cdecl main(INT argc, CHAR **argv) -{ - int i; - double result; - - struct test tests[] = - { - /* Value test result */ - { 0.100000000000, 1.105170918076 }, - { 1.000000000000, 2.718281828459 }, - { 2.400000000000, 11.023176380642 }, - { 3.750000000000, 42.521082000063 }, - { 7.630000000000, 2059.050019837344 }, - { 10.000000000000, 22026.465794806718 }, - { 13.260000000000, 573779.238840227250 }, - { 18.100000000000, 72565488.372322351000 }, - { 25.000000000000, 72004899337.385880000000 }, - { 29.310000000000, 5360079912775.353500000000 } - }; - - double infinite[] = - { - 2215.8, 20554.1 - }; - - - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) - { - return (FAIL); - } - - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) - { - double testDelta; - double allowedDelta; - - result = exp( tests[i].value ); - - /* The test is valid when the difference between the */ - /* result and the expectation is less than DELTA */ - allowedDelta = (tests[i].value > 1) ? 1 : DELTA; - testDelta = fabs( result - tests[i].result ); - if( testDelta >= allowedDelta ) - { - Fail( "exp(%g) returned %20.10g" - " when it should have returned %20.10g\n", - tests[i].value, - result, - tests[i].result ); - } - } - - for( i = 0; i < sizeof(infinite) / sizeof(double); i++) - { - result = exp( infinite[i] ); - - /* The test is valid when the function returns an infinite result */ - if( _finite( result ) ) - { - Fail( "exp(%g) returned %20.10g" - " when it should have returned 1.#INF00000000", - infinite[i], - result ); - } - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/pal/tests/palsuite/c_runtime/expf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/expf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/expf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/exp/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/expf/test1/CMakeLists.txt similarity index 50% rename from src/pal/tests/palsuite/c_runtime/exp/test3/CMakeLists.txt rename to src/pal/tests/palsuite/c_runtime/expf/test1/CMakeLists.txt index 00fbca535201..fb12b65c2fc8 100644 --- a/src/pal/tests/palsuite/c_runtime/exp/test3/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/expf/test1/CMakeLists.txt @@ -3,16 +3,16 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test3.c + test1.c ) -add_executable(paltest_exp_test3 +add_executable(paltest_expf_test1 ${SOURCES} ) -add_dependencies(paltest_exp_test3 coreclrpal) +add_dependencies(paltest_expf_test1 coreclrpal) -target_link_libraries(paltest_exp_test3 +target_link_libraries(paltest_expf_test1 pthread m coreclrpal diff --git a/src/pal/tests/palsuite/c_runtime/expf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/expf/test1/test1.c new file mode 100644 index 000000000000..2d14ae5b84ce --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/expf/test1/test1.c @@ -0,0 +1,123 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Tests expf with a normal set of values. +** +** +**===================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = expf(value); + + /* + * The test is valid when the difference between the + * result and the expfectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("expf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = expf(value); + + if (!isnan(result)) + { + Fail("expf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { -INFINITY, 0, 1e-6f }, // value: -(inf) expected: 0 + { -3.14159265f, 0.0432139183f, 1e-7f }, // value: -(pi) + { -2.71828183f, 0.0659880358f, 1e-7f }, // value: -(e) + { -2.30258509f, 0.1f, 1e-6f }, // value: -(ln(10)) expected: 1 / 10 + { -1.57079633f, 0.207879576f, 1e-6f }, // value: -(pi / 2) + { -1.44269504f, 0.236290088f, 1e-6f }, // value: -(log2(e)) + { -1.41421356f, 0.243116734f, 1e-6f }, // value: -(sqrt(2)) + { -1.12837917f, 0.323557264f, 1e-6f }, // value: -(2 / sqrt(pi)) + { -1, 0.367879441f, 1e-6f }, // value: -(1) + { -0.785398163f, 0.455938128f, 1e-6f }, // value: -(pi / 4) + { -0.707106781f, 0.493068691f, 1e-6f }, // value: -(1 / sqrt(2)) + { -0.693147181f, 0.5f, 1e-6f }, // value: -(ln(2)) expected: 1 / 2 + { -0.636619772f, 0.529077808f, 1e-6f }, // value: -(2 / pi) + { -0.434294482f, 0.647721485f, 1e-6f }, // value: -(log10(e)) + { -0.318309886f, 0.727377349f, 1e-6f }, // value: -(1 / pi) + { 0, 1, 1e-5f }, // value: 0 expected: 1 + { 0.318309886f, 1.37480223f, 1e-5f }, // value: 1 / pi + { 0.434294482f, 1.54387344f, 1e-5f }, // value: log10(e) + { 0.636619772f, 1.89008116f, 1e-5f }, // value: 2 / pi + { 0.693147181f, 2, 1e-5f }, // value: ln(2) expected: 2 + { 0.707106781f, 2.02811498f, 1e-5f }, // value: 1 / sqrt(2) + { 0.785398163f, 2.19328005f, 1e-5f }, // value: pi / 4 + { 1, 2.71828183f, 1e-5f }, // value: 1 expected: e + { 1.12837917f, 3.09064302f, 1e-5f }, // value: 2 / sqrt(pi) + { 1.41421356f, 4.11325038f, 1e-5f }, // value: sqrt(2) + { 1.44269504f, 4.23208611f, 1e-5f }, // value: log2(e) + { 1.57079633f, 4.81047738f, 1e-5f }, // value: pi / 2 + { 2.30258509f, 10, 1e-4f }, // value: ln(10) expected: 10 + { 2.71828183f, 15.1542622f, 1e-4f }, // value: e + { 3.14159265f, 23.1406926f, 1e-4f }, // value: pi + { INFINITY, INFINITY, 0 }, // value: inf expected: inf + }; + + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/exp/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/expf/test1/testinfo.dat similarity index 51% rename from src/pal/tests/palsuite/c_runtime/exp/test2/testinfo.dat rename to src/pal/tests/palsuite/c_runtime/expf/test1/testinfo.dat index 828e033b2018..64063507651a 100644 --- a/src/pal/tests/palsuite/c_runtime/exp/test2/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/expf/test1/testinfo.dat @@ -4,9 +4,9 @@ Version = 1.0 Section = C Runtime -Function = exp -Name = Test #2 for exp +Function = expf +Name = Test #1 for expf Type = DEFAULT -EXE1 = test2 +EXE1 = test1 Description -=Tests that exp handles underflows, overflows, and NaNs correctly. +=Tests expf with a normal set of values. diff --git a/src/pal/tests/palsuite/c_runtime/fabs/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fabs/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/fabs/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fabs/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.c index 56d207e5dc5f..13184005676b 100644 --- a/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/fabs/test1/test1.c @@ -11,9 +11,7 @@ ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail -** - +** Fail ** **===========================================================================*/ @@ -24,10 +22,49 @@ */ struct test { - double value; // param 1 - double result; // expected result + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = fabs(value); + + /* + * The test is valid when the difference between the + * result and the fabsectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("fabs(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = fabs(value); + + if (!isnan(result)) + { + Fail("fabs(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + /** * main * @@ -35,56 +72,42 @@ struct test */ INT __cdecl main(INT argc, CHAR **argv) { - int i; - struct test tests[] = { - // param 1 result - { 3, 3 }, - { -10, 10 }, - { 0, 0 }, - { 1.7e308, 1.7e308 }, - { -1.7e308, 1.7e308 }, - { 4.94e-324, 4.94e-324 }, - { -4.94e-324, 4.94e-324 } + /* value expected variance */ + { -INFINITY, INFINITY, 0 }, + { -3.1415926535897932, 3.1415926535897932, 0.00000000000001 }, // value: -(pi) expected: pi + { -2.7182818284590452, 2.7182818284590452, 0.00000000000001 }, // value: -(e) expected: e + { -2.3025850929940457, 2.3025850929940457, 0.00000000000001 }, // value: -(ln(10)) expected: ln(10) + { -1.5707963267948966, 1.5707963267948966, 0.00000000000001 }, // value: -(pi / 2) expected: pi / 2 + { -1.4426950408889634, 1.4426950408889634, 0.00000000000001 }, // value: -(log2(e)) expected: log2(e) + { -1.4142135623730950, 1.4142135623730950, 0.00000000000001 }, // value: -(sqrt(2)) expected: sqrt(2) + { -1.1283791670955126, 1.1283791670955126, 0.00000000000001 }, // value: -(2 / sqrt(pi)) expected: 2 / sqrt(pi) + { -1, 1, 0.00000000000001 }, + { -0.78539816339744831, 0.78539816339744831, 0.000000000000001 }, // value: -(pi / 4) expected: pi / 4 + { -0.70710678118654752, 0.70710678118654752, 0.000000000000001 }, // value: -(1 / sqrt(2)) expected: 1 / sqrt(2) + { -0.69314718055994531, 0.69314718055994531, 0.000000000000001 }, // value: -(ln(2)) expected: ln(2) + { -0.63661977236758134, 0.63661977236758134, 0.000000000000001 }, // value: -(2 / pi) expected: 2 / pi + { -0.43429448190325183, 0.43429448190325183, 0.000000000000001 }, // value: -(log10(e)) expected: log10(e) + { -0.31830988618379067, 0.31830988618379067, 0.000000000000001 }, // value: -(1 / pi) expected: 1 / pi + { -0.0, 0, 0.000000000000001 }, }; // PAL initialization - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return FAIL; + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++ ) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - - result = fabs( tests[i].value ); - - if( result != tests[i].result ) - { - Fail( "fabs(%f) returned %f" - " when it should have returned %f", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); } + + validate_isnan(NAN); PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/fabs/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fabs/test1/testinfo.dat index 3900743b8805..edb8e6c0454a 100644 --- a/src/pal/tests/palsuite/c_runtime/fabs/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/fabs/test1/testinfo.dat @@ -1,4 +1,4 @@ -# +\# # Copyright (c) Microsoft Corporation. All rights reserved. # @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to fabs() a series of values, checking that = each one return to correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/fabsf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fabsf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fabsf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/fabsf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fabsf/test1/CMakeLists.txt new file mode 100644 index 000000000000..06512ebd7c84 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fabsf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_fabsf_test1 + ${SOURCES} +) + +add_dependencies(paltest_fabsf_test1 coreclrpal) + +target_link_libraries(paltest_fabsf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.c new file mode 100644 index 000000000000..aedf1e29b7f7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fabsf/test1/test1.c @@ -0,0 +1,113 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that fabsf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = fabsf(value); + + /* + * The test is valid when the difference between the + * result and the fabsfectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("fabsf(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = fabsf(value); + + if (!isnan(result)) + { + Fail("fabsf(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +INT __cdecl main(INT argc, CHAR **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { -INFINITY, INFINITY, 0 }, + { -3.14159265f, 3.14159265f, 0.00001f }, // value: -(pi) expected: pi + { -2.71828183f, 2.71828183f, 0.00001f }, // value: -(e) expected: e + { -2.30258509f, 2.30258509f, 0.00001f }, // value: -(ln(10)) expected: ln(10) + { -1.57079633f, 1.57079633f, 0.00001f }, // value: -(pi / 2) expected: pi / 2 + { -1.44269504f, 1.44269504f, 0.00001f }, // value: -(log2(e)) expected: log2(e) + { -1.41421356f, 1.41421356f, 0.00001f }, // value: -(sqrt(2)) expected: sqrt(2) + { -1.12837917f, 1.12837917f, 0.00001f }, // value: -(2 / sqrt(pi)) expected: 2 / sqrt(pi) + { -1, 1, 0.00001f }, + { -0.785398163f, 0.785398163f, 0.000001f }, // value: -(pi / 4) expected: pi / 4 + { -0.707106781f, 0.707106781f, 0.000001f }, // value: -(1 / sqrt(2)) expected: 1 / sqrt(2) + { -0.693147181f, 0.693147181f, 0.000001f }, // value: -(ln(2)) expected: ln(2) + { -0.636619772f, 0.636619772f, 0.000001f }, // value: -(2 / pi) expected: 2 / pi + { -0.434294482f, 0.434294482f, 0.000001f }, // value: -(log10(e)) expected: log10(e) + { -0.318309886f, 0.318309886f, 0.000001f }, // value: -(1 / pi) expected: 1 / pi + { -0.0f, 0, 0.000001f }, + }; + + + // PAL initialization + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fabsf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fabsf/test1/testinfo.dat new file mode 100644 index 000000000000..356097a9fe91 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fabsf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = fabsf +Name = Positive Test for fabsf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to fabsf() a series of values, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/floor/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/floor/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/floor/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/floor/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/floor/test1/test1.c b/src/pal/tests/palsuite/c_runtime/floor/test1/test1.c index 498a7876e3ba..acdfda0458e5 100644 --- a/src/pal/tests/palsuite/c_runtime/floor/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/floor/test1/test1.c @@ -3,19 +3,16 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -/*============================================================================= +/*============================================================================ ** -** Source: test1.c +** Source: test1.c ** -** Purpose: Test to ensure that floor return the correct values -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** - +** Purpose: Tests floor with simple positive and negative values. Also tests +** extreme cases like extremely small values and positive and +** negative infinity. Makes sure that calling floor on NaN returns +** NaN ** -**===========================================================================*/ +**==========================================================================*/ #include @@ -24,70 +21,95 @@ */ struct test { - double value; // floor param 1 - double result; // expected result + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = floor(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("floor(%g) returned %20.15g when it should have returned %20.15g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = floor(value); + + if (!isnan(result)) + { + Fail("floor(%g) returned %20.15g when it should have returned %20.15g", + value, result, NAN); + } +} + /** * main * * executable entry point */ -INT __cdecl main(INT argc, CHAR **argv) +int __cdecl main(int argc, char *argv[]) { - int i; - struct test tests[] = { - // param 1 result - { 3, 3 }, - { -10, -10 }, - { 0, 0 }, - { 1.7e308, 1.7e308 }, - { -1.7e308, -1.7e308 }, - { 4.94e-324, 0 }, - { -4.94e-324, -1 }, - { 1234.1234, 1234 }, - { -1234.1234, -1235 }, - {-0, 0 } + /* value expected variance */ + { 0.31830988618379067, 0, 0.000000000000001 }, // value: 1 / pi + { 0.43429448190325183, 0, 0.000000000000001 }, // value: log10(e) + { 0.63661977236758134, 0, 0.000000000000001 }, // value: 2 / pi + { 0.69314718055994531, 0, 0.000000000000001 }, // value: ln(2) + { 0.70710678118654752, 0, 0.000000000000001 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0, 0.000000000000001 }, // value: pi / 4 + { 1.1283791670955126, 1, 0.00000000000001 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 1, 0.00000000000001 }, // value: sqrt(2) + { 1.4426950408889634, 1, 0.00000000000001 }, // value: log2(e) + { 1.5707963267948966, 1, 0.00000000000001 }, // value: pi / 2 + { 2.3025850929940457, 2, 0.00000000000001 }, // value: ln(10) + { 2.7182818284590452, 2, 0.00000000000001 }, // value: e + { 3.1415926535897932, 3, 0.00000000000001 }, // value: pi + { INFINITY, INFINITY, 0 } }; - - // PAL initialization - if( PAL_Initialize(argc, argv) != 0 ) + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) { - return FAIL; + return FAIL; } - - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + + validate( 0, 0, 0.000000000000001); + validate(-0.0, 0, 0.000000000000001); + + validate( 1, 1, 0.00000000000001); + validate(-1.0, -1, 0.00000000000001); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - - result = floor( tests[i].value ); - - if( result != tests[i].result ) - { - Fail( "floor(%f) returned %f" - " when it should have returned %f", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -(tests[i].expected + 1), tests[i].variance); } + + validate_isnan(NAN); PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/floor/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/floor/test1/testinfo.dat index f3a38611d233..8b778bc44330 100644 --- a/src/pal/tests/palsuite/c_runtime/floor/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/floor/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to floor() a series of value, checking that = each one return to correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/floorf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/floorf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floorf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/floorf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/floorf/test1/CMakeLists.txt new file mode 100644 index 000000000000..f6e24adcd9fb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floorf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_floorf_test1 + ${SOURCES} +) + +add_dependencies(paltest_floorf_test1 coreclrpal) + +target_link_libraries(paltest_floorf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/floorf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/floorf/test1/test1.c new file mode 100644 index 000000000000..bb6d63847700 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floorf/test1/test1.c @@ -0,0 +1,115 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: Tests floorf with simple positive and negative values. Also tests +** extreme cases like extremely small values and positive and +** negative infinity. Makes sure that calling floorf on NaN returns +** NaN +** +**==========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = floorf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("floorf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = floorf(value); + + if (!isnan(result)) + { + Fail("floorf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char *argv[]) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.318309886f, 0, 0.000001f }, // value: 1 / pi + { 0.434294482f, 0, 0.000001f }, // value: log10(e) + { 0.636619772f, 0, 0.000001f }, // value: 2 / pi + { 0.693147181f, 0, 0.000001f }, // value: ln(2) + { 0.707106781f, 0, 0.000001f }, // value: 1 / sqrt(2) + { 0.785398163f, 0, 0.000001f }, // value: pi / 4 + { 1.12837917f, 1, 0.00001f }, // value: 2 / sqrt(pi) + { 1.41421356f, 1, 0.00001f }, // value: sqrt(2) + { 1.44269504f, 1, 0.00001f }, // value: log2(e) + { 1.57079633f, 1, 0.00001f }, // value: pi / 2 + { 2.30258509f, 2, 0.00001f }, // value: ln(10) + { 2.71828183f, 2, 0.00001f }, // value: e + { 3.14159265f, 3, 0.00001f }, // value: pi + { INFINITY, INFINITY, 0 } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate( 0, 0, 0.000001f); + validate(-0.0f, 0, 0.000001f); + + validate( 1, 1, 0.00001f); + validate(-1.0, -1, 0.00001f); + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -(tests[i].expected + 1), tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/floorf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/floorf/test1/testinfo.dat new file mode 100644 index 000000000000..2a71c971b850 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/floorf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = floorf +Name = Positive Test for floorf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to floorf() a series of value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/fmod/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fmod/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/fmod/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/fmod/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.c index 11eb74e4f7f0..fe0555ce939e 100644 --- a/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/fmod/test1/test1.c @@ -11,27 +11,62 @@ ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** - ** **===========================================================================*/ #include -#define DELTA 0.0000001 //Error acceptance level to the 7th decimal - /** * Helper test structure */ struct test { - double valueX; // fmod param 1 - double valueY; // fmod param 2 - double result; // expected result + double numerator; /* second component of the value to test the function with */ + double denominator; /* first component of the value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double numerator, double denominator, double expected, double variance) +{ + double result = fmod(numerator, denominator); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("fmod(%g, %g) returned %20.15g when it should have returned %20.15g", + numerator, denominator, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double numerator, double denominator) +{ + double result = fmod(numerator, denominator); + + if (!isnan(result)) + { + Fail("fmod(%g, %g) returned %20.15g when it should have returned %20.15g", + numerator, denominator, result, NAN); + } +} + /** * main * @@ -39,63 +74,67 @@ struct test */ INT __cdecl main(INT argc, CHAR **argv) { - int i; - struct test tests[] = { - // param 1 param 2 result - { 3, 2, 1 }, - { -10, 3, -1 }, - { 1, 0.0, 0 }, - { 1.7e308, -1.7e308, 0 }, - { 100, -1.1234, 0.017400 }, - { -100, -1.1234, -0.017400}, - { 0, 0, 0 }, - {-0, 1, 0 }, - {-0, -0, 0 } + /* numerator denominator expected variance */ + { 0, INFINITY, 0, 0.000000000000001 }, + { 0.31296179620778659, 0.94976571538163866, 0.31296179620778658, 0.000000000000001 }, + { 0.42077048331375735, 0.90716712923909839, 0.42077048331375733, 0.000000000000001 }, + { 0.59448076852482208, 0.80410982822879171, 0.59448076852482212, 0.000000000000001 }, + { 0.63896127631363480, 0.76923890136397213, 0.63896127631363475, 0.000000000000001 }, + { 0.64963693908006244, 0.76024459707563015, 0.64963693908006248, 0.000000000000001 }, + { 0.70710678118654752, 0.70710678118654752, 0, 0.000000000000001 }, + { 1, 1, 0, 0.000000000000001 }, + { 0.84147098480789651, 0.54030230586813972, 0.30116867893975674, 0.000000000000001 }, + { 0.90371945743584630, 0.42812514788535792, 0.047469161665130377, 0.0000000000000001 }, + { 0.98776594599273553, 0.15594369476537447, 0.052103777400488605, 0.0000000000000001 }, + { 0.99180624439366372, 0.12775121753523991, 0.097547721646984359, 0.0000000000000001 }, + { 0.74398033695749319, -0.66820151019031295, 0.075778826767180285, 0.0000000000000001 }, + { 0.41078129050290870, -0.91173391478696510, 0.41078129050290868, 0.000000000000001 }, + { 0, -1, 0, 0.000000000000001 }, + { 1, INFINITY, 1, 0.00000000000001 }, }; // PAL initialization - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return FAIL; + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++ ) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - double testDelta; - - result = fmod( tests[i].valueX, tests[i].valueY ); - - // The test is valid when the difference between the - // result and the expectation is less than DELTA - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "fmod(%f, %f) returned %f" - " when it should have returned %f", - tests[i].valueX, - tests[i].valueY, - result, - tests[i].result ); - } + validate( tests[i].numerator, tests[i].denominator, tests[i].expected, tests[i].variance); + validate(-tests[i].numerator, tests[i].denominator, -tests[i].expected, tests[i].variance); + validate( tests[i].numerator, -tests[i].denominator, tests[i].expected, tests[i].variance); + validate(-tests[i].numerator, -tests[i].denominator, -tests[i].expected, tests[i].variance); } + validate_isnan( 0, 0); + validate_isnan(-0.0, 0); + validate_isnan( 0, -0.0); + validate_isnan(-0.0, -0.0); + + validate_isnan( 1, 0); + validate_isnan(-1.0, 0); + validate_isnan( 1, -0.0); + validate_isnan(-1.0, -0.0); + + validate_isnan( INFINITY, INFINITY); + validate_isnan(-INFINITY, INFINITY); + validate_isnan( INFINITY, -INFINITY); + validate_isnan(-INFINITY, -INFINITY); + + validate_isnan( INFINITY, 0); + validate_isnan(-INFINITY, 0); + validate_isnan( INFINITY, -0.0); + validate_isnan(-INFINITY, -0.0); + + validate_isnan( INFINITY, 1); + validate_isnan(-INFINITY, 1); + validate_isnan( INFINITY, -1.0); + validate_isnan(-INFINITY, -1.0); + PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/fmod/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fmod/test1/testinfo.dat index 6a80955e3efc..d302fa82dbeb 100644 --- a/src/pal/tests/palsuite/c_runtime/fmod/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/fmod/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to fmod() a series of values, checking that = each one return to correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/fmodf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fmodf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fmodf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/fmodf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/fmodf/test1/CMakeLists.txt new file mode 100644 index 000000000000..d1ea238a98c3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fmodf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_fmodf_test1 + ${SOURCES} +) + +add_dependencies(paltest_fmodf_test1 coreclrpal) + +target_link_libraries(paltest_fmodf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.c new file mode 100644 index 000000000000..9f0376850d80 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fmodf/test1/test1.c @@ -0,0 +1,140 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that fmodf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float numerator; /* second component of the value to test the function with */ + float denominator; /* first component of the value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float numerator, float denominator, float expected, float variance) +{ + float result = fmodf(numerator, denominator); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("fmodf(%g, %g) returned %20.15g when it should have returned %20.15g", + numerator, denominator, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float numerator, float denominator) +{ + float result = fmodf(numerator, denominator); + + if (!isnan(result)) + { + Fail("fmodf(%g, %g) returned %20.15g when it should have returned %20.15g", + numerator, denominator, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +INT __cdecl main(INT argc, CHAR **argv) +{ + struct test tests[] = + { + /* numerator denominator expected variance */ + { 0, INFINITY, 0, 0.000001f }, + { 0.312961796f, 0.949765715f, 0.312961796f, 0.000001f }, + { 0.420770483f, 0.907167129f, 0.420770483f, 0.000001f }, + { 0.594480769f, 0.804109828f, 0.594480769f, 0.000001f }, + { 0.638961276f, 0.769238901f, 0.638961276f, 0.000001f }, + { 0.649636939f, 0.760244597f, 0.649636939f, 0.000001f }, + { 0.707106781f, 0.707106781f, 0, 0.000001f }, + { 1, 1, 0, 0.000001f }, + { 0.841470985f, 0.540302306f, 0.301168679f, 0.000001f }, + { 0.903719457f, 0.428125148f, 0.0474691617f, 0.0000001f }, + { 0.987765946f, 0.155943695f, 0.0521037774f, 0.0000001f }, + { 0.991806244f, 0.127751218f, 0.0975477216f, 0.0000001f }, + { 0.743980337f, -0.668201510f, 0.0757788268f, 0.0000001f }, + { 0.410781291f, -0.911733915f, 0.410781291f, 0.000001f }, + { 0, -1, 0, 0.000001f }, + { 1, INFINITY, 1, 0.00001f }, + }; + + + // PAL initialization + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].numerator, tests[i].denominator, tests[i].expected, tests[i].variance); + validate(-tests[i].numerator, tests[i].denominator, -tests[i].expected, tests[i].variance); + validate( tests[i].numerator, -tests[i].denominator, tests[i].expected, tests[i].variance); + validate(-tests[i].numerator, -tests[i].denominator, -tests[i].expected, tests[i].variance); + } + + validate_isnan( 0, 0); + validate_isnan(-0.0f, 0); + validate_isnan( 0, -0.0f); + validate_isnan(-0.0f, -0.0f); + + validate_isnan( 1, 0); + validate_isnan(-1, 0); + validate_isnan( 1, -0.0f); + validate_isnan(-1, -0.0f); + + validate_isnan( INFINITY, INFINITY); + validate_isnan(-INFINITY, INFINITY); + validate_isnan( INFINITY, -INFINITY); + validate_isnan(-INFINITY, -INFINITY); + + validate_isnan( INFINITY, 0); + validate_isnan(-INFINITY, 0); + validate_isnan( INFINITY, -0.0f); + validate_isnan(-INFINITY, -0.0f); + + validate_isnan( INFINITY, 1); + validate_isnan(-INFINITY, 1); + validate_isnan( INFINITY, -1); + validate_isnan(-INFINITY, -1); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/fmodf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/fmodf/test1/testinfo.dat new file mode 100644 index 000000000000..004da0a636f4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/fmodf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = fmodf +Name = Positive Test for fmodf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to fmodf() a series of values, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/isfinite/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isfinite/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isfinite/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/isfinite/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isfinite/test1/CMakeLists.txt new file mode 100644 index 000000000000..4fc3bfb1879e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isfinite/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_isfinite_test1 + ${SOURCES} +) + +add_dependencies(paltest_isfinite_test1 coreclrpal) + +target_link_libraries(paltest_isfinite_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c b/src/pal/tests/palsuite/c_runtime/isfinite/test1/test1.c similarity index 68% rename from src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c rename to src/pal/tests/palsuite/c_runtime/isfinite/test1/test1.c index ed56f5878bf2..268d4ae53bc4 100644 --- a/src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/isfinite/test1/test1.c @@ -7,23 +7,21 @@ ** ** Source: test1.c ** -** Purpose: Checks that _finite correctly classifies all types +** Purpose: Checks that isfinite correctly classifies all types ** of floating point numbers (NaN, -Infinity, Infinity, ** finite nonzero, unnormalized, 0, and -0) ** -** **==========================================================================*/ - #include /* -The IEEE double precision floating point standard looks like this: +The IEEE double precision floating point stanfdard looks like this: S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0 1 11 12 63 -S is the sign bit. The E bits are the exponent, and the 52 F bits are +S is the sign bit. The E bits are the expfonent, and the 52 F bits are the fraction. These represent a value, V. If E=2047 and F is nonzero, then V=NaN ("Not a number") @@ -70,54 +68,44 @@ int __cdecl main(int argc, char **argv) } /*non-finite numbers*/ - if (_finite(nan) || _finite(nan2)) + if (isfinite(nan) || isfinite(nan2)) { - Fail ("_finite() found NAN to be finite.\n"); + Fail ("isfinite() found NAN to be finite.\n"); } - if (_finite(neginf)) + if (isfinite(neginf)) { - Fail ("_finite() found negative infinity to be finite.\n"); + Fail ("isfinite() found negative infinity to be finite.\n"); } - if (_finite(inf)) + if (isfinite(inf)) { - Fail ("_finite() found infinity to be finite.\n"); + Fail ("isfinite() found infinity to be finite.\n"); } - /*finite numbers*/ - if (!_finite(unnormalized)) + if (!isfinite(unnormalized)) { - Fail ("_finite() found an unnormalized value to be infinite.\n"); + Fail ("isfinite() found an unnormalized value to be infinite.\n"); } - if (!_finite(negUnnormalized)) + if (!isfinite(negUnnormalized)) { - Fail ("_finite() found a negative unnormalized value to be infinite.\n"); + Fail ("isfinite() found a negative unnormalized value to be infinite.\n"); } - if (!_finite((double)0)) + if (!isfinite((double)0)) { - Fail ("_finite found zero to be infinite.\n"); + Fail ("isfinite found zero to be infinite.\n"); } - if (!_finite(negZero)) + if (!isfinite(negZero)) { - Fail ("_finite() found negative zero to be infinite.\n"); + Fail ("isfinite() found negative zero to be infinite.\n"); } - if (!_finite(pos)) + if (!isfinite(pos)) { - Fail ("_finite() found %f to be infinite.\n", pos); + Fail ("isfinite() found %f to be infinite.\n", pos); } - if (!_finite(neg)) + if (!isfinite(neg)) { - Fail ("_finite() found %f to be infinite.\n", neg); + Fail ("isfinite() found %f to be infinite.\n", neg); } PAL_Terminate(); return PASS; } - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/isfinite/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/isfinite/test1/testinfo.dat new file mode 100644 index 000000000000..0a6961d2ddce --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isfinite/test1/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = isfinite +Name = Positive Test for isfinite +TYPE = DEFAULT +EXE1 = test1 +Description +=Checks that isfinite correctly classifies all types of floating +=point numbers +=(NaN, -Infinity, Infinity, finite nonzero, unnormalized, 0, and -0). diff --git a/src/pal/tests/palsuite/c_runtime/_finite/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isinf/CMakeLists.txt similarity index 100% rename from src/pal/tests/palsuite/c_runtime/_finite/CMakeLists.txt rename to src/pal/tests/palsuite/c_runtime/isinf/CMakeLists.txt diff --git a/src/pal/tests/palsuite/c_runtime/isinf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/isinf/test1/CMakeLists.txt new file mode 100644 index 000000000000..01e8c421ef0a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isinf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_isinf_test1 + ${SOURCES} +) + +add_dependencies(paltest_isinf_test1 coreclrpal) + +target_link_libraries(paltest_isinf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/isinf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/isinf/test1/test1.c new file mode 100644 index 000000000000..9469d1af677e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/isinf/test1/test1.c @@ -0,0 +1,123 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: Checks that isinf correctly classifies all types +** of floating point numbers (NaN, -Infinity, Infinity, +** finite nonzero, unnormalized, 0, and -0) +** +** +**==========================================================================*/ + + +#include + +/* +The IEEE double precision floating point stanfdard looks like this: + + S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + 0 1 11 12 63 + +S is the sign bit. The E bits are the expfonent, and the 52 F bits are +the fraction. These represent a value, V. + +If E=2047 and F is nonzero, then V=NaN ("Not a number") +If E=2047 and F is zero and S is 1, then V=-Infinity +If E=2047 and F is zero and S is 0, then V=Infinity +If 0 - #define TO_DOUBLE(a) (*(double*)&a) -#define TO_I64(a) (*(INT64*) &a) +#define TO_I32(a) (*(INT64*) &a) /* - * NaN: any double with maximum exponent (0x7ff) and non-zero fraction + * NaN: any double with maximum expfonent (0x7ff) and non-zero fraction */ int __cdecl main(int argc, char *argv[]) { UINT64 PosInf=0; UINT64 NegInf=0; UINT64 val=0; - /* * Initialize the PAL and return FAIL if this fails */ @@ -41,76 +38,65 @@ int __cdecl main(int argc, char *argv[]) /* * Try some trivial values */ - if (_isnan(0)) + if (isnan(0)) { - Fail ("_isnan() incorrectly identified %f as NaN!\n", 0); + Fail ("isnan() incorrectly identified %f as NaN!\n", 0); } - if (_isnan(1.2423456)) + if (isnan(1.2423456)) { - Fail ("_isnan() incorrectly identified %f as NaN!\n", 0); + Fail ("isnan() incorrectly identified %f as NaN!\n", 0); } - if (_isnan(42)) + if (isnan(42)) { - Fail ("_isnan() incorrectly identified %f as NaN!\n", 0); + Fail ("isnan() incorrectly identified %f as NaN!\n", 0); } - PosInf = 0x7ff00000; PosInf <<=32; - NegInf = 0xfff00000; NegInf <<=32; - /* * Try positive and negative infinity */ - if (_isnan(TO_DOUBLE(PosInf))) + if (isnan(TO_DOUBLE(PosInf))) { - Fail ("_isnan() incorrectly identified %I64x as NaN!\n", PosInf); + Fail ("isnan() incorrectly identified %I32x as NaN!\n", PosInf); } - - if (_isnan(TO_DOUBLE(NegInf))) + if (isnan(TO_DOUBLE(NegInf))) { - Fail ("_isnan() incorrectly identified %I64x as NaN!\n", NegInf); + Fail ("isnan() incorrectly identified %I32x as NaN!\n", NegInf); } - /* * Try setting the least significant bit of the fraction, * positive and negative */ val = PosInf + 1; - if (!_isnan(TO_DOUBLE(val))) + if (!isnan(TO_DOUBLE(val))) { - Fail ("_isnan() failed to identify %I64x as NaN!\n", val); + Fail ("isnan() failed to identify %I32x as NaN!\n", val); } - val = NegInf + 1; - if (!_isnan(TO_DOUBLE(val))) + if (!isnan(TO_DOUBLE(val))) { - Fail ("_isnan() failed to identify %I64x as NaN!\n", val); + Fail ("isnan() failed to identify %I32x as NaN!\n", val); } - /* * Try setting the most significant bit of the fraction, * positive and negative */ val = 0x7ff80000; val <<=32; - if (!_isnan(TO_DOUBLE(val))) + if (!isnan(TO_DOUBLE(val))) { - Fail ("_isnan() failed to identify %I64x as NaN!\n", val); + Fail ("isnan() failed to identify %I32x as NaN!\n", val); } - val = 0xfff80000; val <<=32; - if (!_isnan(TO_DOUBLE(val))) + if (!isnan(TO_DOUBLE(val))) { - Fail ("_isnan() failed to identify %I64x as NaN!\n", val); + Fail ("isnan() failed to identify %I32x as NaN!\n", val); } - PAL_Terminate(); - return PASS; } - diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/isnan/test1/testinfo.dat similarity index 75% rename from src/pal/tests/palsuite/c_runtime/_isnan/test1/testinfo.dat rename to src/pal/tests/palsuite/c_runtime/isnan/test1/testinfo.dat index 19180816074d..c6ad3aa7c61c 100644 --- a/src/pal/tests/palsuite/c_runtime/_isnan/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/isnan/test1/testinfo.dat @@ -4,12 +4,12 @@ Version = 1.0 Section = C Runtime -Function = _isnan -Name = Test #1 for _isnan +Function = isnan +Name = Test #1 for isnan TYPE = DEFAULT EXE1 = test1 Description -= Test _isnan with a number of trivial values, to ensure they indicated that += Test isnan with a number of trivial values, to ensure they indicated that = they are numbers. Then try with Positive/Negative Infinite, which should = also be numbers. Finally set the least and most significant bits of = the fraction to positive and negative, at which point it should return diff --git a/src/pal/tests/palsuite/c_runtime/log/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/log/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/log/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/log/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/log/test1/test1.c b/src/pal/tests/palsuite/c_runtime/log/test1/test1.c index b1b9737f4c0b..63f413672e1b 100644 --- a/src/pal/tests/palsuite/c_runtime/log/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/log/test1/test1.c @@ -3,130 +3,121 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -/*============================================================================= +/*===================================================================== ** -** Source: test1.c +** Source: test1.c +** +** Purpose: Tests log with a normal set of values. ** -** Purpose: Test to ensure that log returns correct values. -** -** Dependencies: PAL_Initialize -** PAL_Terminate -** Fail -** fabs -** _finite -** _isnan -** - ** -**===========================================================================*/ +**===================================================================*/ #include -#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; /** - * main - * - * executable entry point + * validate + * + * test validation function */ -INT __cdecl main(INT argc, CHAR **argv) +void __cdecl validate(double value, double expected, double variance) { - int i; - double result; + double result = log(value); - struct test tests[] = - { - /* Value test result */ - { 4.812768944365, 1.571272582596 }, - { 25.873592333750, 3.253222847545 }, - { 30.301828058718, 3.411208042666 }, - { 53.752250740074, 3.984385540365 }, - { 65.282143620106, 4.178718547435 }, - { 74.843592638936, 4.315400504515 }, - { 92.446668904691, 4.526631925866 }, - { 99.832148197882, 4.603490257677 }, - { 1830.360576189459, 7.512268262595 }, - { 6524.430494094669, 8.783308947783 }, - { 12456.186254463331, 9.429972666394 }, - { 14183.841639454329, 9.559858682961 }, - { 18221.999603259377, 9.810384912501 }, - { 20792.917264320811, 9.942367691562 }, - { 26488.001312295906, 10.184447128770 }, - { 29724.154423657950, 10.299715274515 }, - { 27899211.434430983, 17.144108982393 }, - { 55048606.214117862, 17.823727102268 }, - { 66659312.564470351, 18.015105318226 }, - { 113314373.84325695, 18.545676583294 }, - { 201366015.49641407, 19.120634782682 }, - { 311568417.23368025, 19.557129510064 }, - { 486835298.54176462, 20.003436427833 }, - }; + /* + * The test is valid when the difference between the + * result and the logectation is less than DELTA + */ + double delta = fabs(result - expected); - double indefinite[] = + if ((delta != 0) && (delta >= variance)) { - -864278.51, -1000.2, -2 - }; + Fail("log(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = log(value); - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (!isnan(result)) { - return (FAIL); + Fail("log(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); } +} - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = { - double testDelta; - - result = log( tests[i].value ); + /* value expected variance */ + { 0, -INFINITY, 0 }, // expected: -(inf) value: 0 + { 0.043213918263772250, -3.1415926535897932, 1e-14 }, // expected: -(pi) + { 0.065988035845312537, -2.7182818284590452, 1e-14 }, // expected: -(e) + { 0.1, -2.3025850929940457, 1e-14 }, // expected: -(ln(10)) value: 1 / 10 + { 0.20787957635076191, -1.5707963267948966, 1e-14 }, // expected: -(pi / 2) + { 0.23629008834452270, -1.4426950408889634, 1e-14 }, // expected: -(log2(e)) + { 0.24311673443421421, -1.4142135623730950, 1e-14 }, // expected: -(sqrt(2)) + { 0.32355726390307110, -1.1283791670955126, 1e-14 }, // expected: -(2 / sqrt(pi)) + { 0.36787944117144232, -1, 1e-14 }, // expected: -(1) + { 0.45593812776599624, -0.78539816339744831, 1e-15 }, // expected: -(pi / 4) + { 0.49306869139523979, -0.70710678118654752, 1e-15 }, // expected: -(1 / sqrt(2)) + { 0.5, -0.69314718055994531, 1e-15 }, // expected: -(ln(2)) value: 1 / 2 + { 0.52907780826773535, -0.63661977236758134, 1e-15 }, // expected: -(2 / pi) + { 0.64772148514180065, -0.43429448190325183, 1e-15 }, // expected: -(log10(e)) + { 0.72737734929521647, -0.31830988618379067, 1e-15 }, // expected: -(1 / pi) + { 1, 0, 1e-15 }, // expected: 0 value: 1 + { 1.3748022274393586, 0.31830988618379067, 1e-15 }, // expected: 1 / pi + { 1.5438734439711811, 0.43429448190325183, 1e-15 }, // expected: log10(e) + { 1.8900811645722220, 0.63661977236758134, 1e-15 }, // expected: 2 / pi + { 2, 0.69314718055994531, 1e-15 }, // expected: ln(2) value: 2 + { 2.0281149816474725, 0.70710678118654752, 1e-15 }, // expected: 1 / sqrt(2) + { 2.1932800507380155, 0.78539816339744831, 1e-15 }, // expected: pi / 4 + { 2.7182818284590452, 1, 1e-14 }, // value: e + { 3.0906430223107976, 1.1283791670955126, 1e-14 }, // expected: 2 / sqrt(pi) + { 4.1132503787829275, 1.4142135623730950, 1e-14 }, // expected: sqrt(2) + { 4.2320861065570819, 1.4426950408889634, 1e-14 }, // expected: log2(e) + { 4.8104773809653517, 1.5707963267948966, 1e-14 }, // expected: pi / 2 + { 10, 2.3025850929940457, 1e-14 }, // expected: ln(10) value: 10 + { 15.154262241479264, 2.7182818284590452, 1e-14 }, // expected: e + { 23.140692632779269, 3.1415926535897932, 1e-14 }, // expected: pi + { INFINITY, INFINITY, 0 }, // expected: inf value: inf + }; - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "log(%g) returned %20.10f" - " when it should have returned %20.10f", - tests[i].value, - result, - tests[i].result ); - } - } - for( i = 0; i < sizeof(indefinite) / sizeof(double); i++) + if (PAL_Initialize(argc, argv) != 0) { - result = log( indefinite[i] ); - - /* The test is valid when the function returns a defined result */ - if( ! _isnan( result ) ) - { - Fail( "log(%g) returned %20.10f" - " when it should have returned -1.#IND00000000", - indefinite[i], - result ); - } + return FAIL; } - /* log(0) is a special case */ - result = log( 0.0 ); - if( _finite( result ) ) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - Fail( "log(%g) returned %20.10f" - " when it should have returned -1.#INF00000000", - 0.0, - result ); + validate(tests[i].value, tests[i].expected, tests[i].variance); } + + validate_isnan(-INFINITY); + validate_isnan( NAN); PAL_Terminate(); return PASS; diff --git a/src/pal/tests/palsuite/c_runtime/log/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/log/test1/testinfo.dat index a51a23791e19..58ae62db1bf2 100644 --- a/src/pal/tests/palsuite/c_runtime/log/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/log/test1/testinfo.dat @@ -12,6 +12,3 @@ Description = Passes a series of values to the log() function, = checking each for the expected result. Also checks = for proper handling of out-of-range values. - - - diff --git a/src/pal/tests/palsuite/c_runtime/log10/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/log10/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/log10/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/log10/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/log10/test1/test1.c b/src/pal/tests/palsuite/c_runtime/log10/test1/test1.c index 6aaf1e2037e2..c2a3004cfef7 100644 --- a/src/pal/tests/palsuite/c_runtime/log10/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/log10/test1/test1.c @@ -13,8 +13,8 @@ ** PAL_Terminate ** Fail ** fabs -** _finite -** _isnan +** isfinite +** isnan ** ** @@ -112,7 +112,7 @@ INT __cdecl main(INT argc, CHAR **argv) result = log10( indefinite[i] ); /* The test is valid when the function returns a defined result */ - if( ! _isnan( result ) ) + if( ! isnan( result ) ) { Fail( "log10(%g) returned %20.10f" " when it should have returned -1.#IND00000000", @@ -123,7 +123,7 @@ INT __cdecl main(INT argc, CHAR **argv) /* log(0) is a special case */ result = log10( 0.0 ); - if( _finite( result ) ) + if( isfinite( result ) ) { Fail( "log10(%g) returned %20.10f" " when it should have returned -1.#INF00000000", diff --git a/src/pal/tests/palsuite/c_runtime/logf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/logf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/logf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/logf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/logf/test1/CMakeLists.txt new file mode 100644 index 000000000000..550f572bc7ad --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/logf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_logf_test1 + ${SOURCES} +) + +add_dependencies(paltest_logf_test1 coreclrpal) + +target_link_libraries(paltest_logf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/logf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/logf/test1/test1.c new file mode 100644 index 000000000000..95b9708415ee --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/logf/test1/test1.c @@ -0,0 +1,124 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Tests logf with a normal set of values. +** +** +**===================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = logf(value); + + /* + * The test is valid when the difference between the + * result and the logfectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("logf(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = logf(value); + + if (!isnan(result)) + { + Fail("logf(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, -INFINITY, 0 }, // expected: -(inf) value: 0 + { 0.0432139183f, -3.14159265f, 1e-5f }, // expected: -(pi) + { 0.0659880358f, -2.71828183f, 1e-5f }, // expected: -(e) + { 0.1f, -2.30258509f, 1e-5f }, // expected: -(ln(10)) value: 1 / 10 + { 0.207879576f, -1.57079633f, 1e-5f }, // expected: -(pi / 2) + { 0.236290088f, -1.44269504f, 1e-5f }, // expected: -(log2(e)) + { 0.243116734f, -1.41421356f, 1e-5f }, // expected: -(sqrt(2)) + { 0.323557264f, -1.12837917f, 1e-5f }, // expected: -(2 / sqrt(pi)) + { 0.367879441f, -1, 1e-5f }, // expected: -(1) + { 0.455938128f, -0.785398163f, 1e-6f }, // expected: -(pi / 4) + { 0.493068691f, -0.707106781f, 1e-6f }, // expected: -(1 / sqrt(2)) + { 0.5f, -0.693147181f, 1e-6f }, // expected: -(ln(2)) value: 1 / 2 + { 0.529077808f, -0.636619772f, 1e-6f }, // expected: -(2 / pi) + { 0.647721485f, -0.434294482f, 1e-6f }, // expected: -(log10(e)) + { 0.727377349f, -0.318309886f, 1e-6f }, // expected: -(1 / pi) + { 1, 0, 1e-6f }, // expected: 0 value: 1 + { 1.37480223f, 0.318309886f, 1e-6f }, // expected: 1 / pi + { 1.54387344f, 0.434294482f, 1e-6f }, // expected: log10(e) + { 1.89008116f, 0.636619772f, 1e-6f }, // expected: 2 / pi + { 2, 0.693147181f, 1e-6f }, // expected: ln(2) value: 2 + { 2.02811498f, 0.707106781f, 1e-6f }, // expected: 1 / sqrt(2) + { 2.19328005f, 0.785398163f, 1e-6f }, // expected: pi / 4 + { 2.71828183f, 1, 1e-5f }, // expected: 1 value: e + { 3.09064302f, 1.12837917f, 1e-5f }, // expected: 2 / sqrt(pi) + { 4.11325038f, 1.41421356f, 1e-5f }, // expected: sqrt(2) + { 4.23208611f, 1.44269504f, 1e-5f }, // expected: log2(e) + { 4.81047738f, 1.57079633f, 1e-5f }, // expected: pi / 2 + { 10, 2.30258509f, 1e-5f }, // expected: ln(10) value: 10 + { 15.1542622f, 2.71828183f, 1e-5f }, // expected: e + { 23.1406926f, 3.14159265f, 1e-5f }, // expected: pi + { INFINITY, INFINITY, 0 }, // expected: inf value: inf + }; + + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate(tests[i].value, tests[i].expected, tests[i].variance); + } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/exp/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/logf/test1/testinfo.dat similarity index 67% rename from src/pal/tests/palsuite/c_runtime/exp/test3/testinfo.dat rename to src/pal/tests/palsuite/c_runtime/logf/test1/testinfo.dat index 2f9dbcbf2da2..b3710abea7f0 100644 --- a/src/pal/tests/palsuite/c_runtime/exp/test3/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/logf/test1/testinfo.dat @@ -4,14 +4,11 @@ Version = 1.0 Section = C Runtime -Function = exp -Name = Positive Test for exp +Function = logf +Name = Positive Test for logf TYPE = DEFAULT -EXE1 = test3 +EXE1 = test1 Description -= Passes a series of values to the exp() function, += Passes a series of values to the logf() function, = checking each for the expected result. Also checks = for proper handling of out-of-range values. - - - diff --git a/src/pal/tests/palsuite/c_runtime/pow/test2/test2.c b/src/pal/tests/palsuite/c_runtime/pow/test2/test2.c index 94691af6abc6..22a7dea2de8d 100644 --- a/src/pal/tests/palsuite/c_runtime/pow/test2/test2.c +++ b/src/pal/tests/palsuite/c_runtime/pow/test2/test2.c @@ -170,7 +170,7 @@ int __cdecl main(int argc, char **argv) { result = pow(retNaN[i].Number, retNaN[i].Exponent); - if ( ! _isnan(result) ) + if ( ! isnan(result) ) { Fail("ERROR: pow took '%f' to the exponent '%f' " "to be %f instead of %f.\n", diff --git a/src/pal/tests/palsuite/c_runtime/pow/test3/test3.c b/src/pal/tests/palsuite/c_runtime/pow/test3/test3.c index e459e783ce44..d5fe74450dee 100644 --- a/src/pal/tests/palsuite/c_runtime/pow/test3/test3.c +++ b/src/pal/tests/palsuite/c_runtime/pow/test3/test3.c @@ -13,8 +13,8 @@ ** PAL_Terminate ** Fail ** fabs -** _finite -** _isnan +** isfinite +** isnan ** ** @@ -107,7 +107,7 @@ int __cdecl main(int argc, char **argv) result = pow( infinite[i].value, infinite[i].exponent ); /* The test is valid when the function returns an infinite result */ - if( _finite( result ) ) + if( isfinite( result ) ) { Fail( "pow(%g,%g) returned %20.10g" " when it should have returned 1.#INF00000000", diff --git a/src/pal/tests/palsuite/c_runtime/sin/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sin/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/sin/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/sin/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/sin/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sin/test1/test1.c index 118d20c3492e..ac99ebf0a2bd 100644 --- a/src/pal/tests/palsuite/c_runtime/sin/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/sin/test1/test1.c @@ -11,93 +11,104 @@ ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** - ** **===========================================================================*/ #include -#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = sin(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("sin(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = sin(value); + + if (!isnan(result)) + { + Fail("sin(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + /** * main * * executable entry point */ -INT __cdecl main(INT argc, CHAR **argv) +int __cdecl main(int argc, char **argv) { - double pi = 3.1415926535; - int i; - struct test tests[] = { - /* Value test result */ - { 0, 0 }, - { pi/2.0, 1 }, - { pi, 0 }, - { (3.0*pi) / 2.0, -1 }, - { 2.0 * pi, 0 }, - { 5.0*pi/2.0, 1 }, - { 3.0*pi, 0 }, - { (7.0*pi) / 2.0, -1 }, - { 4.0 * pi, 0 } + /* value expected variance */ + { 0, 0, 0.000000000000001 }, + { 0.31830988618379067, 0.31296179620778659, 0.000000000000001 }, // value: 1 / pi + { 0.43429448190325183, 0.42077048331375735, 0.000000000000001 }, // value: log10(e) + { 0.63661977236758134, 0.59448076852482208, 0.000000000000001 }, // value: 2 / pi + { 0.69314718055994531, 0.63896127631363480, 0.000000000000001 }, // value: ln(2) + { 0.70710678118654752, 0.64963693908006244, 0.000000000000001 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.70710678118654752, 0.000000000000001 }, // value: pi / 4, expected: 1 / sqrt(2) + { 1, 0.84147098480789651, 0.000000000000001 }, + { 1.1283791670955126, 0.90371945743584630, 0.000000000000001 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 0.98776594599273553, 0.000000000000001 }, // value: sqrt(2) + { 1.4426950408889634, 0.99180624439366372, 0.000000000000001 }, // value: log2(e) + { 1.5707963267948966, 1, 0.00000000000001 }, // value: pi / 2 + { 2.3025850929940457, 0.74398033695749319, 0.000000000000001 }, // value: ln(10) + { 2.7182818284590452, 0.41078129050290870, 0.000000000000001 }, // value: e + { 3.1415926535897932, 0, 0.000000000000001 }, // value: pi }; - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return (FAIL); + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - double testDelta; - - - result = sin( tests[i].value ); - - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "sin(%g) returned %g" - " when it should have returned %g", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/sin/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sin/test1/testinfo.dat index f6cd39a9b20b..f2a974fc39ff 100644 --- a/src/pal/tests/palsuite/c_runtime/sin/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/sin/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to sin() a series of angle value, checking that = each one return to correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/sinf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/sinf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinf/test1/CMakeLists.txt new file mode 100644 index 000000000000..0651b43d1d0f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_sinf_test1 + ${SOURCES} +) + +add_dependencies(paltest_sinf_test1 coreclrpal) + +target_link_libraries(paltest_sinf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sinf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sinf/test1/test1.c new file mode 100644 index 000000000000..826689633b27 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinf/test1/test1.c @@ -0,0 +1,114 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that sinf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = sinf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("sinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = sinf(value); + + if (!isnan(result)) + { + Fail("sinf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000001f }, + { 0.318309886f, 0.312961796f, 0.000001f }, // value: 1 / pi + { 0.434294482f, 0.420770483f, 0.000001f }, // value: log10(e) + { 0.636619772f, 0.594480769f, 0.000001f }, // value: 2 / pi + { 0.693147181f, 0.638961276f, 0.000001f }, // value: ln(2) + { 0.707106781f, 0.649636939f, 0.000001f }, // value: 1 / sqrt(2) + { 0.785398163f, 0.707106781f, 0.000001f }, // value: pi / 4, expected: 1 / sqrt(2) + { 1, 0.841470985f, 0.000001f }, + { 1.12837917f, 0.903719457f, 0.000001f }, // value: 2 / sqrt(pi) + { 1.41421356f, 0.987765946f, 0.000001f }, // value: sqrt(2) + { 1.44269504f, 0.991806244f, 0.000001f }, // value: log2(e) + { 1.57079633f, 1, 0.00001f }, // value: pi / 2 + { 2.30258509f, 0.743980337f, 0.000001f }, // value: ln(10) + { 2.71828183f, 0.410781291f, 0.000001f }, // value: e + { 3.14159265f, 0, 0.000001f }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sinf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sinf/test1/testinfo.dat new file mode 100644 index 000000000000..a94dcf21a7c6 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = sinf +Name = Positive Test for sinf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to sinf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/sinh/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinh/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/sinh/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/sinh/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.c index efc1c5170380..f92aeb5f5817 100644 --- a/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/sinh/test1/test1.c @@ -11,93 +11,103 @@ ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** - ** **===========================================================================*/ #include -#define DELTA 0.0000001 /*Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = sinh(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("sinh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = sinh(value); + + if (!isnan(result)) + { + Fail("sinh(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + /** * main * * executable entry point */ -INT __cdecl main(INT argc, CHAR **argv) +int __cdecl main(int argc, char **argv) { - double pi = 3.1415926535; - int i; - struct test tests[] = { - /* Value test result */ - { 0, 0 }, - { pi/2.0, 2.3012989 }, - { pi, 11.5487394 }, - { (3.0*pi) / 2.0, 55.6543976 }, - { 2.0 * pi, 267.7448940 }, - { 5.0*pi/2.0, 1287.9850539 }, - { 3.0*pi, 6195.8238619 }, - { (7.0*pi) / 2.0, 29804.8707287 }, - { 4.0 * pi, 143375.6565151 } + /* value expected variance */ + { 0, 0, 0.000000000000001 }, + { 0.31830988618379067, 0.32371243907207108, 0.000000000000001 }, // value: 1 / pi + { 0.43429448190325183, 0.44807597941469025, 0.000000000000001 }, // value: log10(e) + { 0.63661977236758134, 0.68050167815224332, 0.000000000000001 }, // value: 2 / pi + { 0.69314718055994531, 0.75, 0.000000000000001 }, // value: ln(2) + { 0.70710678118654752, 0.76752314512611633, 0.000000000000001 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.86867096148600961, 0.000000000000001 }, // value: pi / 4 + { 1, 1.1752011936438015, 0.00000000000001 }, + { 1.1283791670955126, 1.3835428792038633, 0.00000000000001 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 1.9350668221743567, 0.00000000000001 }, // value: sqrt(2) + { 1.4426950408889634, 1.9978980091062796, 0.00000000000001 }, // value: log2(e) + { 1.5707963267948966, 2.3012989023072949, 0.00000000000001 }, // value: pi / 2 + { 2.3025850929940457, 4.95, 0.00000000000001 }, // value: ln(10) + { 2.7182818284590452, 7.5441371028169758, 0.00000000000001 }, // value: e + { 3.1415926535897932, 11.548739357257748, 0.0000000000001 }, // value: pi + { INFINITY, INFINITY, 0 }, }; - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return (FAIL); + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - double testDelta; - - - result = sinh( tests[i].value ); - - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "sinh(%g) returned %g" - " when it should have returned %g", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); } + + validate_isnan(NAN); PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/sinh/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sinh/test1/testinfo.dat index dd4d6f8c909a..d3a4833b0f21 100644 --- a/src/pal/tests/palsuite/c_runtime/sinh/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/sinh/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to sinh() a series of angle value, checking that = each one return to correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/sinhf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinhf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinhf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/sinhf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/sinhf/test1/CMakeLists.txt new file mode 100644 index 000000000000..72cce4346086 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinhf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_sinhf_test1 + ${SOURCES} +) + +add_dependencies(paltest_sinhf_test1 coreclrpal) + +target_link_libraries(paltest_sinhf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/sinhf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/sinhf/test1/test1.c new file mode 100644 index 000000000000..5420ef0bea15 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinhf/test1/test1.c @@ -0,0 +1,113 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that sinhf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = sinhf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("sinhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = sinhf(value); + + if (!isnan(result)) + { + Fail("sinhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000001f }, + { 0.318309886f, 0.323712439f, 0.000001f }, // value: 1 / pi + { 0.434294482f, 0.448075979f, 0.000001f }, // value: log10(e) + { 0.636619772f, 0.680501678f, 0.000001f }, // value: 2 / pi + { 0.693147181f, 0.75f, 0.000001f }, // value: ln(2) + { 0.707106781f, 0.767523145f, 0.000001f }, // value: 1 / sqrt(2) + { 0.785398163f, 0.868670961f, 0.000001f }, // value: pi / 4 + { 1, 1.17520119f, 0.00001f }, + { 1.12837917f, 1.38354288f, 0.00001f }, // value: 2 / sqrt(pi) + { 1.41421356f, 1.93506682f, 0.00001f }, // value: sqrt(2) + { 1.44269504f, 1.99789801f, 0.00001f }, // value: log2(e) + { 1.57079633f, 2.30129890f, 0.00001f }, // value: pi / 2 + { 2.30258509f, 4.95f, 0.00001f }, // value: ln(10) + { 2.71828183f, 7.54413710f, 0.00001f }, // value: e + { 3.14159265f, 11.5487394f, 0.0001f }, // value: pi + { INFINITY, INFINITY, 0 }, + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/sinhf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/sinhf/test1/testinfo.dat new file mode 100644 index 000000000000..bca33d8a994e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/sinhf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = sinhf +Name = Positive Test for sinhf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to sinhf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/tan/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tan/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/tan/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/tan/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/tan/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tan/test1/test1.c index 6b070aac1576..35bd33078992 100644 --- a/src/pal/tests/palsuite/c_runtime/tan/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/tan/test1/test1.c @@ -11,90 +11,110 @@ ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** - ** **===========================================================================*/ #include -#define DELTA 0.0000001 /*Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = tan(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("tan(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = tan(value); + + if (!isnan(result)) + { + Fail("tan(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + /** * main * * executable entry point */ -INT __cdecl main(INT argc, CHAR **argv) +int __cdecl main(int argc, char **argv) { - int i; - struct test tests[] = { - /* Value test result */ - { 0.001, 0.001 }, - { 0.05, 0.050041708 }, - { 0.5, 0.54630249 }, - { 1, 1.557407725 }, - { 2, -2.185039863 }, - { 3, -0.142546543 }, - { 4, 1.157821282 } + /* value expected variance */ + { 0, 0, 0.000000000000001 }, + { 0.31830988618379067, 0.32951473309607836, 0.000000000000001 }, // value: 1 / pi + { 0.43429448190325183, 0.46382906716062964, 0.000000000000001 }, // value: log10(e) + { 0.63661977236758134, 0.73930295048660405, 0.000000000000001 }, // value: 2 / pi + { 0.69314718055994531, 0.83064087786078395, 0.000000000000001 }, // value: ln(2) + { 0.70710678118654752, 0.85451043200960189, 0.000000000000001 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 1, 0.00000000000001 }, // value: pi / 4 + { 1, 1.5574077246549022, 0.00000000000001 }, + { 1.1283791670955126, 2.1108768356626451, 0.00000000000001 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 6.3341191670421916, 0.00000000000001 }, // value: sqrt(2) + { 1.4426950408889634, 7.7635756709721848, 0.00000000000001 }, // value: log2(e) + // SEE BELOW -- { 1.5707963267948966, INFINITY, 0 }, // value: pi / 2 + { 2.3025850929940457, -1.1134071468135374, 0.00000000000001 }, // value: ln(10) + { 2.7182818284590452, -0.45054953406980750, 0.000000000000001 }, // value: e + { 3.1415926535897932, 0, 0.000000000000001 }, // value: pi }; - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return (FAIL); + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - double testDelta; - - - result = tan( tests[i].value ); - - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "tan(%g) returned %g" - " when it should have returned %g", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); } + + // -- SPECIAL CASE -- + // Normally, tan(pi / 2) would return INFINITY (atan2(INFINITY) does return (pi / 2)). + // However, it seems instead (on all supported systems), we get a different number entirely. + validate( 1.5707963267948966, 16331239353195370.0, 0); + validate(-1.5707963267948966, -16331239353195370.0, 0); + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/tan/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/tan/test1/testinfo.dat index e34c00f9e2ba..16b7703bded2 100644 --- a/src/pal/tests/palsuite/c_runtime/tan/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/tan/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to tan() a series of angle value, checking that = each one return to correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/tanf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/tanf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanf/test1/CMakeLists.txt new file mode 100644 index 000000000000..cd588ea23e7e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_tanf_test1 + ${SOURCES} +) + +add_dependencies(paltest_tanf_test1 coreclrpal) + +target_link_libraries(paltest_tanf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/tanf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tanf/test1/test1.c new file mode 100644 index 000000000000..316ee86fe7c1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanf/test1/test1.c @@ -0,0 +1,120 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that tanf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = tanf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("tanf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = tanf(value); + + if (!isnan(result)) + { + Fail("tanf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000001f }, + { 0.318309886f, 0.329514733f, 0.000001f }, // value: 1 / pi + { 0.434294482f, 0.463829067f, 0.000001f }, // value: log10(e) + { 0.636619772f, 0.739302950f, 0.000001f }, // value: 2 / pi + { 0.693147181f, 0.830640878f, 0.000001f }, // value: ln(2) + { 0.707106781f, 0.854510432f, 0.000001f }, // value: 1 / sqrt(2) + { 0.785398163f, 1, 0.00001f }, // value: pi / 4 + { 1, 1.55740772f, 0.00001f }, + { 1.12837917f, 2.11087684f, 0.00001f }, // value: 2 / sqrt(pi) + { 1.41421356f, 6.33411917f, 0.00001f }, // value: sqrt(2) + { 1.44269504f, 7.76357567f, 0.00001f }, // value: log2(e) + // SEE BELOW -- { 1.57079633f, INFINITY, 0 }, // value: pi / 2 + { 2.30258509f, -1.11340715f, 0.00001f }, // value: ln(10) + { 2.71828183f, -0.450549534f, 0.000001f }, // value: e + { 3.14159265f, 0, 0.000001f }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + // -- SPECIAL CASE -- + // Normally, tanf(pi / 2) would return INFINITY (atan2f(INFINITY) does return (pi / 2)). + // However, it seems instead (on all supported systems), we get a different number entirely. + validate( 1.57079633f, -22877332.0f, 0); + validate(-1.57079633f, 22877332.0f, 0); + + validate_isnan(-INFINITY); + validate_isnan( NAN); + validate_isnan( INFINITY); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/tanf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/tanf/test1/testinfo.dat new file mode 100644 index 000000000000..39a1b303de7e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = tanf +Name = Positive Test for tanf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to tanf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/c_runtime/tanh/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanh/CMakeLists.txt index f6aa0cb2d9da..5e1ef7f28b2f 100644 --- a/src/pal/tests/palsuite/c_runtime/tanh/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/tanh/CMakeLists.txt @@ -1,4 +1,3 @@ cmake_minimum_required(VERSION 2.8.12.2) add_subdirectory(test1) - diff --git a/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.c index 0af2f6264608..88c507911ae7 100644 --- a/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.c +++ b/src/pal/tests/palsuite/c_runtime/tanh/test1/test1.c @@ -11,93 +11,103 @@ ** ** Dependencies: PAL_Initialize ** PAL_Terminate -** Fail +** Fail ** fabs -** - ** **===========================================================================*/ #include -#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */ - /** * Helper test structure */ struct test { - double value; /* value to test the function with */ - double result; /* expected result */ + double value; /* value to test the function with */ + double expected; /* expected result */ + double variance; /* maximum delta between the expected and actual result */ }; +/** + * validate + * + * test validation function + */ +void __cdecl validate(double value, double expected, double variance) +{ + double result = tanh(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + double delta = fabs(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("tanh(%g) returned %20.17g when it should have returned %20.17g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(double value) +{ + double result = tanh(value); + + if (!isnan(result)) + { + Fail("tanh(%g) returned %20.17g when it should have returned %20.17g", + value, result, NAN); + } +} + /** * main * * executable entry point */ -INT __cdecl main(INT argc, CHAR **argv) +int __cdecl main(int argc, char **argv) { - double pi = 3.1415926535; - int i; - struct test tests[] = { - /* Value test result */ - { 0, 0 }, - { pi/2.0, 0.9171523 }, - { pi, 0.9962721 }, - { (3.0*pi) / 2.0, 0.9998386 }, - { 2.0 * pi, 0.9999930 }, - { 5.0*pi/2.0, 0.9999997 }, - { 3.0*pi, 1 }, - { (7.0*pi) / 2.0, 1 }, - { 4.0 * pi, 1 } + /* value expected variance */ + { 0, 0, 0.000000000000001 }, + { 0.31830988618379067, 0.30797791269089433, 0.000000000000001 }, // value: 1 / pi + { 0.43429448190325183, 0.40890401183401433, 0.000000000000001 }, // value: log10(e) + { 0.63661977236758134, 0.56259360033158334, 0.000000000000001 }, // value: 2 / pi + { 0.69314718055994531, 0.6, 0.000000000000001 }, // value: ln(2) + { 0.70710678118654752, 0.60885936501391381, 0.000000000000001 }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.65579420263267244, 0.000000000000001 }, // value: pi / 4 + { 1, 0.76159415595576489, 0.000000000000001 }, + { 1.1283791670955126, 0.81046380599898809, 0.000000000000001 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 0.88838556158566054, 0.000000000000001 }, // value: sqrt(2) + { 1.4426950408889634, 0.89423894585503855, 0.000000000000001 }, // value: log2(e) + { 1.5707963267948966, 0.91715233566727435, 0.000000000000001 }, // value: pi / 2 + { 2.3025850929940457, 0.98019801980198020, 0.000000000000001 }, // value: ln(10) + { 2.7182818284590452, 0.99132891580059984, 0.000000000000001 }, // value: e + { 3.1415926535897932, 0.99627207622074994, 0.000000000000001 }, // value: pi + { INFINITY, 1, 0.00000000000001 } }; - /* PAL initialization */ - if( PAL_Initialize(argc, argv) != 0 ) + if (PAL_Initialize(argc, argv) != 0) { - return (FAIL); + return FAIL; } - for( i = 0; i < sizeof(tests) / sizeof(struct test); i++) + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) { - double result; - double testDelta; - - - result = tanh( tests[i].value ); - - /* - * The test is valid when the difference between the - * result and the expectation is less than DELTA - */ - testDelta = fabs( result - tests[i].result ); - if( testDelta >= DELTA ) - { - Fail( "tanh(%g) returned %g" - " when it should have returned %g", - tests[i].value, - result, - tests[i].result ); - } + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); } + + validate_isnan(NAN); PAL_Terminate(); return PASS; } - - - - - - - - - - - - - diff --git a/src/pal/tests/palsuite/c_runtime/tanh/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/tanh/test1/testinfo.dat index 94b32a05ccf8..f160d62804ec 100644 --- a/src/pal/tests/palsuite/c_runtime/tanh/test1/testinfo.dat +++ b/src/pal/tests/palsuite/c_runtime/tanh/test1/testinfo.dat @@ -11,6 +11,3 @@ EXE1 = test1 Description = Passes to tanh() a series of angle value, checking that = each one return to correct value. - - - diff --git a/src/pal/tests/palsuite/c_runtime/tanhf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanhf/CMakeLists.txt new file mode 100644 index 000000000000..5e1ef7f28b2f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanhf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/tanhf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/tanhf/test1/CMakeLists.txt new file mode 100644 index 000000000000..fd0af2a46ff5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanhf/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_tanhf_test1 + ${SOURCES} +) + +add_dependencies(paltest_tanhf_test1 coreclrpal) + +target_link_libraries(paltest_tanhf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/tanhf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/tanhf/test1/test1.c new file mode 100644 index 000000000000..71a94add34bb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanhf/test1/test1.c @@ -0,0 +1,113 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that tanhf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabsf +** +**===========================================================================*/ + +#include + +/** + * Helper test structure + */ +struct test +{ + float value; /* value to test the function with */ + float expected; /* expected result */ + float variance; /* maximum delta between the expected and actual result */ +}; + +/** + * validate + * + * test validation function + */ +void __cdecl validate(float value, float expected, float variance) +{ + float result = tanhf(value); + + /* + * The test is valid when the difference between the + * result and the expectation is less than DELTA + */ + float delta = fabsf(result - expected); + + if ((delta != 0) && (delta >= variance)) + { + Fail("tanhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, expected); + } +} + +/** + * validate + * + * test validation function for values returning NaN + */ +void __cdecl validate_isnan(float value) +{ + float result = tanhf(value); + + if (!isnan(result)) + { + Fail("tanhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, 0.000001f }, + { 0.318309886f, 0.307977913f, 0.000001f }, // value: 1 / pi + { 0.434294482f, 0.408904011f, 0.000001f }, // value: log10(e) + { 0.636619772f, 0.562593600f, 0.000001f }, // value: 2 / pi + { 0.693147181f, 0.6f, 0.000001f }, // value: ln(2) + { 0.707106781f, 0.608859365f, 0.000001f }, // value: 1 / sqrt(2) + { 0.785398163f, 0.655794203f, 0.000001f }, // value: pi / 4 + { 1, 0.761594156f, 0.000001f }, + { 1.12837917f, 0.810463806f, 0.000001f }, // value: 2 / sqrt(pi) + { 1.41421356f, 0.888385562f, 0.000001f }, // value: sqrt(2) + { 1.44269504f, 0.894238946f, 0.000001f }, // value: log2(e) + { 1.57079633f, 0.917152336f, 0.000001f }, // value: pi / 2 + { 2.30258509f, 0.980198020f, 0.000001f }, // value: ln(10) + { 2.71828183f, 0.991328916f, 0.000001f }, // value: e + { 3.14159265f, 0.996272076f, 0.000001f }, // value: pi + { INFINITY, 1, 0.00001f } + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + for (int i = 0; i < (sizeof(tests) / sizeof(struct test)); i++) + { + validate( tests[i].value, tests[i].expected, tests[i].variance); + validate(-tests[i].value, -tests[i].expected, tests[i].variance); + } + + validate_isnan(NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/tanhf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/tanhf/test1/testinfo.dat new file mode 100644 index 000000000000..187bc19c461c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/tanhf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = C Runtime +Function = tanhf +Name = Positive Test for tanhf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes to tanhf() a series of angle value, checking that += each one return to correct value. diff --git a/src/pal/tests/palsuite/paltestlist.txt b/src/pal/tests/palsuite/paltestlist.txt index dd14f757f5c4..225f5f9f02e3 100644 --- a/src/pal/tests/palsuite/paltestlist.txt +++ b/src/pal/tests/palsuite/paltestlist.txt @@ -1,23 +1,36 @@ c_runtime/abs/test1/paltest_abs_test1 c_runtime/acos/test1/paltest_acos_test1 +c_runtime/acosf/test1/paltest_acosf_test1 +c_runtime/acosh/test1/paltest_acosh_test1 +c_runtime/acoshf/test1/paltest_acoshf_test1 c_runtime/asin/test1/paltest_asin_test1 +c_runtime/asinf/test1/paltest_asinf_test1 +c_runtime/asinh/test1/paltest_asinh_test1 +c_runtime/asinhf/test1/paltest_asinhf_test1 c_runtime/atan/test1/paltest_atan_test1 +c_runtime/atanf/test1/paltest_atanf_test1 +c_runtime/atanh/test1/paltest_atanh_test1 +c_runtime/atanhf/test1/paltest_atanhf_test1 c_runtime/atan2/test1/paltest_atan2_test1 +c_runtime/atan2f/test1/paltest_atan2f_test1 c_runtime/atof/test1/paltest_atof_test1 c_runtime/atoi/test1/paltest_atoi_test1 c_runtime/atol/test1/paltest_atol_test1 c_runtime/bsearch/test1/paltest_bsearch_test1 c_runtime/bsearch/test2/paltest_bsearch_test2 c_runtime/ceil/test1/paltest_ceil_test1 +c_runtime/ceilf/test1/paltest_ceilf_test1 c_runtime/cos/test1/paltest_cos_test1 +c_runtime/cosf/test1/paltest_cosf_test1 c_runtime/cosh/test1/paltest_cosh_test1 +c_runtime/coshf/test1/paltest_coshf_test1 c_runtime/errno/test1/paltest_errno_test1 c_runtime/errno/test2/paltest_errno_test2 c_runtime/exit/test1/paltest_exit_test1 c_runtime/exp/test1/paltest_exp_test1 -c_runtime/exp/test2/paltest_exp_test2 -c_runtime/exp/test3/paltest_exp_test3 +c_runtime/expf/test1/paltest_expf_test1 c_runtime/fabs/test1/paltest_fabs_test1 +c_runtime/fabs/test1/paltest_fabsf_test1 c_runtime/fclose/test1/paltest_fclose_test1 c_runtime/fclose/test2/paltest_fclose_test2 c_runtime/fflush/test1/paltest_fflush_test1 @@ -25,7 +38,9 @@ c_runtime/fgets/test1/paltest_fgets_test1 c_runtime/fgets/test2/paltest_fgets_test2 c_runtime/fgets/test3/paltest_fgets_test3 c_runtime/floor/test1/paltest_floor_test1 +c_runtime/floorf/test1/paltest_floorf_test1 c_runtime/fmod/test1/paltest_fmod_test1 +c_runtime/fmod/test1/paltest_fmodf_test1 c_runtime/fopen/test1/paltest_fopen_test1 c_runtime/fopen/test2/paltest_fopen_test2 c_runtime/fopen/test3/paltest_fopen_test3 @@ -79,7 +94,10 @@ c_runtime/getenv/test3/paltest_getenv_test3 c_runtime/isalnum/test1/paltest_isalnum_test1 c_runtime/isalpha/test1/paltest_isalpha_test1 c_runtime/isdigit/test1/paltest_isdigit_test1 +c_runtime/isfinite/test1/paltest_isfinite_test1 +c_runtime/isinf/test1/paltest_isinf_test1 c_runtime/islower/test1/paltest_islower_test1 +c_runtime/isnan/test1/paltest_isnan_test1 c_runtime/isprint/test1/paltest_isprint_test1 c_runtime/isprint/test2/paltest_isprint_test2 c_runtime/isspace/test1/paltest_isspace_test1 @@ -93,6 +111,7 @@ c_runtime/labs/test1/paltest_labs_test1 c_runtime/llabs/test1/paltest_llabs_test1 c_runtime/localtime/test1/paltest_localtime_test1 c_runtime/log/test1/paltest_log_test1 +c_runtime/logf/test1/paltest_logf_test1 c_runtime/log10/test1/paltest_log10_test1 c_runtime/malloc/test1/paltest_malloc_test1 c_runtime/malloc/test2/paltest_malloc_test2 @@ -129,7 +148,9 @@ c_runtime/qsort/test2/paltest_qsort_test2 c_runtime/rand_srand/test1/paltest_rand_srand_test1 c_runtime/realloc/test1/paltest_realloc_test1 c_runtime/sin/test1/paltest_sin_test1 +c_runtime/sinf/test1/paltest_sinf_test1 c_runtime/sinh/test1/paltest_sinh_test1 +c_runtime/sinhf/test1/paltest_sinhf_test1 c_runtime/sprintf/test1/paltest_sprintf_test1 c_runtime/sprintf/test10/paltest_sprintf_test10 c_runtime/sprintf/test11/paltest_sprintf_test11 @@ -219,7 +240,9 @@ c_runtime/swscanf/test7/paltest_swscanf_test7 c_runtime/swscanf/test8/paltest_swscanf_test8 c_runtime/swscanf/test9/paltest_swscanf_test9 c_runtime/tan/test1/paltest_tan_test1 +c_runtime/tanf/test1/paltest_tanf_test1 c_runtime/tanh/test1/paltest_tanh_test1 +c_runtime/tanhf/test1/paltest_tanhf_test1 c_runtime/time/test1/paltest_time_test1 c_runtime/tolower/test1/paltest_tolower_test1 c_runtime/toupper/test1/paltest_toupper_test1 @@ -328,9 +351,7 @@ c_runtime/wcstoul/test6/paltest_wcstoul_test6 c_runtime/wprintf/test1/paltest_wprintf_test1 c_runtime/_alloca/test1/paltest_alloca_test1 c_runtime/_fdopen/test1/paltest_fdopen_test1 -c_runtime/_finite/test1/paltest_finite_test1 c_runtime/_fullpath/test1/paltest_fullpath_test1 -c_runtime/_isnan/test1/paltest_isnan_test1 c_runtime/_itow/test1/paltest_itow_test1 c_runtime/_makepath/test1/paltest_makepath_test1 c_runtime/_mbsdec/test1/paltest_mbsdec_test1 diff --git a/src/pal/tests/palsuite/palverify.dat b/src/pal/tests/palsuite/palverify.dat index a9971578de3d..e398faf8cc04 100644 --- a/src/pal/tests/palsuite/palverify.dat +++ b/src/pal/tests/palsuite/palverify.dat @@ -6,12 +6,10 @@ c_runtime/__iscsym/test1,1 c_runtime/_alloca/test1,1 c_runtime/_ecvt/test1,1 c_runtime/_fdopen/test1,1 -c_runtime/_finite/test1,1 c_runtime/_fullpath/test1,1 c_runtime/_gcvt/test1,1 c_runtime/_gcvt/test2,1 c_runtime/_getw/test1,1 -c_runtime/_isnan/test1,1 c_runtime/_itow/test1,1 c_runtime/_makepath/test1,1 c_runtime/_mbsdec/test1,1 @@ -123,17 +121,30 @@ c_runtime/_wsplitpath/test1,1 c_runtime/_wtoi/test1,1 c_runtime/abs/test1,1 c_runtime/acos/test1,1 +c_runtime/acosf/test1,1 +c_runtime/acosh/test1,1 +c_runtime/acoshf/test1,1 c_runtime/asin/test1,1 +c_runtime/asinf/test1,1 +c_runtime/asinh/test1,1 +c_runtime/asinhf/test1,1 c_runtime/atan/test1,1 +c_runtime/atanf/test1,1 +c_runtime/atanh/test1,1 +c_runtime/atanhf/test1,1 c_runtime/atan2/test1,1 +c_runtime/atan2f/test1,1 c_runtime/atof/test1,1 c_runtime/atoi/test1,1 c_runtime/atol/test1,1 c_runtime/bsearch/test1,1 c_runtime/bsearch/test2,1 c_runtime/ceil/test1,1 +c_runtime/ceilf/test1,1 c_runtime/cos/test1,1 +c_runtime/cosf/test1,1 c_runtime/cosh/test1,1 +c_runtime/coshf/test1,1 c_runtime/ctime/test1,1 c_runtime/errno/test1,1 c_runtime/errno/test2,1 @@ -152,6 +163,7 @@ c_runtime/fgets/test1,1 c_runtime/fgets/test2,1 c_runtime/fgets/test3,1 c_runtime/floor/test1,1 +c_runtime/floorf/test1,1 c_runtime/fmod/test1,1 c_runtime/fopen/test1,1 c_runtime/fopen/test2,1 @@ -214,7 +226,9 @@ c_runtime/getenv/test3,1 c_runtime/isalnum/test1,1 c_runtime/isalpha/test1,1 c_runtime/isdigit/test1,1 +c_runtime/isfinite/test1,1 c_runtime/islower/test1,1 +c_runtime/isnan/test1,1 c_runtime/isprint/test1,1 c_runtime/isprint/test2,1 c_runtime/isspace/test1,1 @@ -264,7 +278,9 @@ c_runtime/qsort/test2,1 c_runtime/rand_srand/test1,1 c_runtime/realloc/test1,1 c_runtime/sin/test1,1 +c_runtime/sinf/test1,1 c_runtime/sinh/test1,1 +c_runtime/sinhf/test1,1 c_runtime/sprintf/test1,1 c_runtime/sprintf/test2,1 c_runtime/sprintf/test3,1 @@ -356,7 +372,9 @@ c_runtime/swscanf/test15,1 c_runtime/swscanf/test16,1 c_runtime/swscanf/test17,1 c_runtime/tan/test1,1 +c_runtime/tanf/test1,1 c_runtime/tanh/test1,1 +c_runtime/tanhf/test1,1 c_runtime/time/test1,1 c_runtime/tolower/test1,1 c_runtime/toupper/test1,1 diff --git a/src/vm/jithelpers.cpp b/src/vm/jithelpers.cpp index a1ba4beee523..ccb0b7125165 100644 --- a/src/vm/jithelpers.cpp +++ b/src/vm/jithelpers.cpp @@ -553,12 +553,12 @@ ftype BankersRound(ftype value) #endif // Else return the nearest even integer - return (ftype)_copysign(ceil(fabs(value+0.5)), + return (ftype)copysign(ceil(fabs(value+0.5)), value); } // Otherwise round to closest - return (ftype)_copysign(floor(fabs(value)+0.5), + return (ftype)copysign(floor(fabs(value)+0.5), value); } @@ -709,12 +709,12 @@ HCIMPL2_VV(float, JIT_FltRem, float dividend, float divisor) // ***"negated for -infinity" has been removed from the spec // - if (divisor==0 || !_finite(dividend)) + if (divisor==0 || !isfinite(dividend)) { UINT32 NaN = CLR_NAN_32; return *(float *)(&NaN); } - else if (!_finite(divisor) && !_isnan(divisor)) + else if (!isfinite(divisor) && !isnan(divisor)) { return dividend; } @@ -742,12 +742,12 @@ HCIMPL2_VV(double, JIT_DblRem, double dividend, double divisor) // // ***"negated for -infinity" has been removed from the spec // - if (divisor==0 || !_finite(dividend)) + if (divisor==0 || !isfinite(dividend)) { UINT64 NaN = CLR_NAN_64; return *(double *)(&NaN); } - else if (!_finite(divisor) && !_isnan(divisor)) + else if (!isfinite(divisor) && !isnan(divisor)) { return dividend; }