From 994d45fc1d2e9844e9345a1f25198edcceff0b99 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Sat, 9 Dec 2017 17:11:07 -0800 Subject: Adding some PAL tests for acosh, asinh, atanh, and cbrt --- src/pal/tests/palsuite/c_runtime/CMakeLists.txt | 8 ++ .../tests/palsuite/c_runtime/acosh/CMakeLists.txt | 3 + .../palsuite/c_runtime/acosh/test1/CMakeLists.txt | 17 +++ .../tests/palsuite/c_runtime/acosh/test1/test1.cpp | 129 ++++++++++++++++++ .../palsuite/c_runtime/acosh/test1/testinfo.dat | 14 ++ .../tests/palsuite/c_runtime/acoshf/CMakeLists.txt | 3 + .../palsuite/c_runtime/acoshf/test1/CMakeLists.txt | 17 +++ .../tests/palsuite/c_runtime/acoshf/test1/test1.c | 128 ++++++++++++++++++ .../palsuite/c_runtime/acoshf/test1/testinfo.dat | 14 ++ .../tests/palsuite/c_runtime/asinh/CMakeLists.txt | 3 + .../palsuite/c_runtime/asinh/test1/CMakeLists.txt | 17 +++ .../tests/palsuite/c_runtime/asinh/test1/test1.cpp | 146 +++++++++++++++++++++ .../palsuite/c_runtime/asinh/test1/testinfo.dat | 14 ++ .../tests/palsuite/c_runtime/asinhf/CMakeLists.txt | 3 + .../palsuite/c_runtime/asinhf/test1/CMakeLists.txt | 17 +++ .../tests/palsuite/c_runtime/asinhf/test1/test1.c | 145 ++++++++++++++++++++ .../palsuite/c_runtime/asinhf/test1/testinfo.dat | 14 ++ .../tests/palsuite/c_runtime/atanh/CMakeLists.txt | 3 + .../palsuite/c_runtime/atanh/test1/CMakeLists.txt | 17 +++ .../tests/palsuite/c_runtime/atanh/test1/test1.cpp | 130 ++++++++++++++++++ .../palsuite/c_runtime/atanh/test1/testinfo.dat | 13 ++ .../tests/palsuite/c_runtime/atanhf/CMakeLists.txt | 3 + .../palsuite/c_runtime/atanhf/test1/CMakeLists.txt | 17 +++ .../tests/palsuite/c_runtime/atanhf/test1/test1.c | 129 ++++++++++++++++++ .../palsuite/c_runtime/atanhf/test1/testinfo.dat | 13 ++ .../tests/palsuite/c_runtime/cbrt/CMakeLists.txt | 4 + .../palsuite/c_runtime/cbrt/test1/CMakeLists.txt | 17 +++ .../tests/palsuite/c_runtime/cbrt/test1/test1.cpp | 123 +++++++++++++++++ .../palsuite/c_runtime/cbrt/test1/testinfo.dat | 17 +++ .../tests/palsuite/c_runtime/cbrtf/CMakeLists.txt | 4 + .../palsuite/c_runtime/cbrtf/test1/CMakeLists.txt | 17 +++ .../tests/palsuite/c_runtime/cbrtf/test1/test1.c | 122 +++++++++++++++++ .../palsuite/c_runtime/cbrtf/test1/testinfo.dat | 17 +++ src/pal/tests/palsuite/paltestlist.txt | 8 ++ src/pal/tests/palsuite/palverify.dat | 8 ++ 35 files changed, 1354 insertions(+) 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.cpp 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/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.cpp 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/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.cpp 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/cbrt/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/cbrt/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/cbrt/test1/test1.cpp create mode 100644 src/pal/tests/palsuite/c_runtime/cbrt/test1/testinfo.dat create mode 100644 src/pal/tests/palsuite/c_runtime/cbrtf/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/cbrtf/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/c_runtime/cbrtf/test1/test1.c create mode 100644 src/pal/tests/palsuite/c_runtime/cbrtf/test1/testinfo.dat (limited to 'src/pal') diff --git a/src/pal/tests/palsuite/c_runtime/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/CMakeLists.txt index 64ac174a97..ba11c91096 100644 --- a/src/pal/tests/palsuite/c_runtime/CMakeLists.txt +++ b/src/pal/tests/palsuite/c_runtime/CMakeLists.txt @@ -3,16 +3,24 @@ 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(atan2) add_subdirectory(atan2f) add_subdirectory(atanf) +add_subdirectory(atanh) +add_subdirectory(atanhf) add_subdirectory(atof) add_subdirectory(atoi) add_subdirectory(atol) add_subdirectory(bsearch) +add_subdirectory(cbrt) +add_subdirectory(cbrtf) add_subdirectory(ceil) add_subdirectory(ceilf) add_subdirectory(cos) 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 0000000000..5e1ef7f28b --- /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 0000000000..0c233d10e7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosh/test1/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_acosh_test1 + ${SOURCES} +) + +add_dependencies(paltest_acosh_test1 coreclrpal) + +target_link_libraries(paltest_acosh_test1 + ${COMMON_TEST_LIBRARIES} +) diff --git a/src/pal/tests/palsuite/c_runtime/acosh/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/acosh/test1/test1.cpp new file mode 100644 index 0000000000..14ff430c05 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosh/test1/test1.cpp @@ -0,0 +1,129 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that acosh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * 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 result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (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, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 1, 0, PAL_EPSILON }, + { 1.0510897883672876, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 1.0957974645564909, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) + { 1.2095794864199787, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 1.25, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 1.2605918365213561, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 1.3246090892520058, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 + { 1.5430806348152438, 1, PAL_EPSILON * 10 }, + { 1.7071001431069344, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 2.1781835566085709, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 2.2341880974508023, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { 2.5091784786580568, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { 5.05, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) + { 7.6101251386622884, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e + { 11.591953275521521, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi + { PAL_POSINF, PAL_POSINF, 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(PAL_NAN); + + 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 0000000000..32d69ee474 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acosh/test1/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = acosh +Name = Positive Test for acosh +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the acosh() 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/acoshf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/acoshf/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /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 0000000000..5f3d42db4e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acoshf/test1/CMakeLists.txt @@ -0,0 +1,17 @@ +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 + ${COMMON_TEST_LIBRARIES} +) 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 0000000000..2209999736 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acoshf/test1/test1.c @@ -0,0 +1,128 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that acoshf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * 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 result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (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 (!_isnanf(result)) + { + Fail("acoshf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 1, 0, PAL_EPSILON }, + { 1.05108979f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 1.09579746f, 0.434294482f, PAL_EPSILON }, // expected: log10f(e) + { 1.20957949f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 1.25f, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 1.26059184f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 1.32460909f, 0.785398163f, PAL_EPSILON }, // expected: pi / 4 + { 1.54308063f, 1, PAL_EPSILON * 10 }, + { 1.70710014f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 2.17818356f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 2.23418810f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { 2.50917848f, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { 5.05f, 2.30258509f, PAL_EPSILON * 10 }, // expected: ln(10) + { 7.61012514f, 2.71828183f, PAL_EPSILON * 10 }, // expected: e + { 11.5919533f, 3.14159265f, PAL_EPSILON * 100 }, // expected: pi + { PAL_POSINF, PAL_POSINF, 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(PAL_NAN); + + 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 0000000000..07d78ad106 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/acoshf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = acoshf +Name = Positive Test for acoshf +TYPE = DEFAULT +EXE1 = test1 +Description += Passes a series of values to the acoshf() 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 0000000000..5e1ef7f28b --- /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 0000000000..c4e07c28bc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinh/test1/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_asinh_test1 + ${SOURCES} +) + +add_dependencies(paltest_asinh_test1 coreclrpal) + +target_link_libraries(paltest_asinh_test1 + ${COMMON_TEST_LIBRARIES} +) diff --git a/src/pal/tests/palsuite/c_runtime/asinh/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/asinh/test1/test1.cpp new file mode 100644 index 0000000000..64c1e4a74f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinh/test1/test1.cpp @@ -0,0 +1,146 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that asinh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * 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 result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (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, PAL_NAN); + } +} + +/** + * validate + * + * test validation function for values returning +INF + */ +void __cdecl validate_isinf_positive(double value) +{ + double result = asinh(value); + + if (result != PAL_POSINF) + { + Fail("asinh(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_POSINF); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.32371243907207108, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 0.44807597941469025, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) + { 0.68050167815224332, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 0.75, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 0.76752314512611633, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 0.86867096148600961, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 + { 1.1752011936438015, 1, PAL_EPSILON * 10 }, + { 1.3835428792038633, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 1.9350668221743567, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 1.9978980091062796, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { 2.3012989023072949, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { 4.95, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) + { 7.5441371028169758, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e + { 11.548739357257748, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi + { PAL_POSINF, PAL_POSINF, 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(PAL_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 0000000000..c5e9530d92 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinh/test1/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +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 0000000000..5e1ef7f28b --- /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 0000000000..9e20ba52d0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinhf/test1/CMakeLists.txt @@ -0,0 +1,17 @@ +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 + ${COMMON_TEST_LIBRARIES} +) 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 0000000000..6ecb8d93ce --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinhf/test1/test1.c @@ -0,0 +1,145 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that asinhf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * 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 result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (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 (!_isnanf(result)) + { + Fail("asinhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * validate + * + * test validation function for values returning +INF + */ +void __cdecl validate_isinf_positive(float value) +{ + float result = asinhf(value); + + if (result != PAL_POSINF) + { + Fail("asinhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_POSINF); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.323712439f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 0.448075979f, 0.434294482f, PAL_EPSILON }, // expected: log10f(e) + { 0.680501678f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 0.75, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 0.767523145f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 0.868670961f, 0.785398163f, PAL_EPSILON }, // expected: pi / 4 + { 1.17520119f, 1, PAL_EPSILON * 10 }, + { 1.38354288f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 1.93506682f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 1.99789801f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { 2.30129890f, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { 4.95f, 2.30258509f, PAL_EPSILON * 10 }, // expected: ln(10) + { 7.54413710f, 2.71828183f, PAL_EPSILON * 10 }, // expected: e + { 11.5487394f, 3.14159265f, PAL_EPSILON * 10 }, // expected: pi + { PAL_POSINF, PAL_POSINF, 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(PAL_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 0000000000..023796b144 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/asinhf/test1/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +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 expected result. Also checks += for proper handling of out-of-range values. 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 0000000000..5e1ef7f28b --- /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 0000000000..62b76943fd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanh/test1/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_atanh_test1 + ${SOURCES} +) + +add_dependencies(paltest_atanh_test1 coreclrpal) + +target_link_libraries(paltest_atanh_test1 + ${COMMON_TEST_LIBRARIES} +) diff --git a/src/pal/tests/palsuite/c_runtime/atanh/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/atanh/test1/test1.cpp new file mode 100644 index 0000000000..d454f3272c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanh/test1/test1.cpp @@ -0,0 +1,130 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that atanh return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * 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 result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (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, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.30797791269089433, 0.31830988618379067, PAL_EPSILON }, // expected: 1 / pi + { 0.40890401183401433, 0.43429448190325183, PAL_EPSILON }, // expected: log10(e) + { 0.56259360033158334, 0.63661977236758134, PAL_EPSILON }, // expected: 2 / pi + { 0.6, 0.69314718055994531, PAL_EPSILON }, // expected: ln(2) + { 0.60885936501391381, 0.70710678118654752, PAL_EPSILON }, // expected: 1 / sqrt(2) + { 0.65579420263267244, 0.78539816339744831, PAL_EPSILON }, // expected: pi / 4 + { 0.76159415595576489, 1, PAL_EPSILON * 10 }, + { 0.81046380599898809, 1.1283791670955126, PAL_EPSILON * 10 }, // expected: 2 / sqrt(pi) + { 0.88838556158566054, 1.4142135623730950, PAL_EPSILON * 10 }, // expected: sqrt(2) + { 0.89423894585503855, 1.4426950408889634, PAL_EPSILON * 10 }, // expected: log2(e) + { 0.91715233566727435, 1.5707963267948966, PAL_EPSILON * 10 }, // expected: pi / 2 + { 0.98019801980198020, 2.3025850929940457, PAL_EPSILON * 10 }, // expected: ln(10) + { 0.99132891580059984, 2.7182818284590452, PAL_EPSILON * 10 }, // expected: e + { 0.99627207622074994, 3.1415926535897932, PAL_EPSILON * 10 }, // expected: pi + { 1, PAL_POSINF, PAL_EPSILON * 10 } + }; + + /* 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(PAL_NAN); + + 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 0000000000..55e1db7c0c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanh/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +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 0000000000..5e1ef7f28b --- /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 0000000000..07809ee522 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanhf/test1/CMakeLists.txt @@ -0,0 +1,17 @@ +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 + ${COMMON_TEST_LIBRARIES} +) 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 0000000000..3fd3ab8bdb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanhf/test1/test1.c @@ -0,0 +1,129 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================= +** +** Source: test1.c +** +** Purpose: Test to ensure that atanhf return the correct values +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** Fail +** fabs +** +**===========================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * 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 result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (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 (!_isnanf(result)) + { + Fail("atanhf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +/** + * main + * + * executable entry point + */ +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0, 0, PAL_EPSILON }, + { 0.307977913f, 0.318309886f, PAL_EPSILON }, // expected: 1 / pi + { 0.408904012f, 0.434294482f, PAL_EPSILON }, // expected: log10f(e) + { 0.562593600f, 0.636619772f, PAL_EPSILON }, // expected: 2 / pi + { 0.6f, 0.693147181f, PAL_EPSILON }, // expected: ln(2) + { 0.608859365f, 0.707106781f, PAL_EPSILON }, // expected: 1 / sqrtf(2) + { 0.655794203f, 0.785398163f, PAL_EPSILON }, // expected: pi / 4 + { 0.761594156f, 1, PAL_EPSILON * 10 }, + { 0.810463806f, 1.12837917f, PAL_EPSILON * 10 }, // expected: 2 / sqrtf(pi) + { 0.888385562f, 1.41421356f, PAL_EPSILON * 10 }, // expected: sqrtf(2) + { 0.894238946f, 1.44269504f, PAL_EPSILON * 10 }, // expected: logf2(e) + { 0.917152336f, 1.57079633f, PAL_EPSILON * 10 }, // expected: pi / 2 + { 0.980198020f, 2.30258509f, PAL_EPSILON * 10 }, // expected: ln(10) + { 0.991328916f, 2.71828183f, PAL_EPSILON * 10 }, // expected: e + { 0.996272076f, 3.14159265f, PAL_EPSILON * 10 }, // expected: pi + { 1, PAL_POSINF, PAL_EPSILON * 10 } + }; + + /* 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(PAL_NAN); + + 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 0000000000..842c0d9ecf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/atanhf/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +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 expected result. diff --git a/src/pal/tests/palsuite/c_runtime/cbrt/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cbrt/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cbrt/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/cbrt/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cbrt/test1/CMakeLists.txt new file mode 100644 index 0000000000..3d100e5663 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cbrt/test1/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_cbrt_test1 + ${SOURCES} +) + +add_dependencies(paltest_cbrt_test1 coreclrpal) + +target_link_libraries(paltest_cbrt_test1 + ${COMMON_TEST_LIBRARIES} +) diff --git a/src/pal/tests/palsuite/c_runtime/cbrt/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/cbrt/test1/test1.cpp new file mode 100644 index 0000000000..471b6a4641 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cbrt/test1/test1.cpp @@ -0,0 +1,123 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Call the cbrt function on a positive value, a positive value +** with a decimal and on the maxium possible double value. +** +** +**===================================================================*/ + +#include + +// binary64 (double) has a machine epsilon of 2^-52 (approx. 2.22e-16). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-50 (approx. 8.88e-16) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (15-17 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxxxxxxxxxx will use +// PAL_EPSILON for the variance, while an expected result in the format of 0.0xxxxxxxxxxxxxxxxx +// will use PAL_EPSILON / 10 and and expected result in the format of x.xxxxxxxxxxxxxxxx will +// use PAL_EPSILON * 10. +#define PAL_EPSILON 8.8817841970012523e-16 + +#define PAL_NAN sqrt(-1.0) +#define PAL_POSINF -log(0.0) +#define PAL_NEGINF log(0.0) + +/** + * 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 = cbrt(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + double delta = fabs(result - expected); + + if (delta > variance) + { + Fail("cbrt(%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 = cbrt(value); + + if (!_isnan(result)) + { + Fail("cbrt(%g) returned %20.17g when it should have returned %20.17g", + value, result, PAL_NAN); + } +} + +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.31830988618379067, 0.68278406325529568, PAL_EPSILON }, // value: 1 / pi + { 0.43429448190325183, 0.75728863133090766, PAL_EPSILON }, // value: log10(e) + { 0.63661977236758134, 0.86025401382809963, PAL_EPSILON }, // value: 2 / pi + { 0.69314718055994531, 0.88499704450051772, PAL_EPSILON }, // value: ln(2) + { 0.70710678118654752, 0.89089871814033930, PAL_EPSILON }, // value: 1 / sqrt(2) + { 0.78539816339744831, 0.92263507432201421, PAL_EPSILON }, // value: pi / 4 + { 1, 1, PAL_EPSILON * 10 }, + { 1.1283791670955126, 1.0410821966965807, PAL_EPSILON * 10 }, // value: 2 / sqrt(pi) + { 1.4142135623730950, 1.1224620483093730, PAL_EPSILON * 10 }, // value: sqrt(2) + { 1.4426950408889634, 1.1299472763373901, PAL_EPSILON * 10 }, // value: log2(e) + { 1.5707963267948966, 1.1624473515096265, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.3025850929940457, 1.3205004784536852, PAL_EPSILON * 10 }, // value: ln(10) + { 2.7182818284590452, 1.3956124250860895, PAL_EPSILON * 10 }, // value: e + { 3.1415926535897932, 1.4645918875615233, PAL_EPSILON * 10 }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate(-0.0, -0.0, PAL_EPSILON); + validate( 0.0, 0.0, PAL_EPSILON); + + 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(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/cbrt/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/cbrt/test1/testinfo.dat new file mode 100644 index 0000000000..ddb926ae17 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cbrt/test1/testinfo.dat @@ -0,0 +1,17 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = cbrt +Name = Call cbrt on positive values and zero. +TYPE = DEFAULT +EXE1 = test1 +Description += Call the cbrt function on a positive value, a positive value += with a decimal and on the maxium possible double value. + + + + diff --git a/src/pal/tests/palsuite/c_runtime/cbrtf/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cbrtf/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cbrtf/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/cbrtf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/cbrtf/test1/CMakeLists.txt new file mode 100644 index 0000000000..c83aa325f5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cbrtf/test1/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_cbrtf_test1 + ${SOURCES} +) + +add_dependencies(paltest_cbrtf_test1 coreclrpal) + +target_link_libraries(paltest_cbrtf_test1 + ${COMMON_TEST_LIBRARIES} +) diff --git a/src/pal/tests/palsuite/c_runtime/cbrtf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/cbrtf/test1/test1.c new file mode 100644 index 0000000000..b13d829fbb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cbrtf/test1/test1.c @@ -0,0 +1,122 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Call the cbrtf function on a positive value, a positive value +** with a decimal and on the maxium possible float value. +** +** +**===================================================================*/ + +#include + +// binary32 (float) has a machine epsilon of 2^-23 (approx. 1.19e-07). However, this +// is slightly too accurate when writing tests meant to run against libm implementations +// for various platforms. 2^-21 (approx. 4.76e-07) seems to be as accurate as we can get. +// +// The tests themselves will take PAL_EPSILON and adjust it according to the expected result +// so that the delta used for comparison will compare the most significant digits and ignore +// any digits that are outside the double precision range (6-9 digits). + +// For example, a test with an expect result in the format of 0.xxxxxxxxx will use PAL_EPSILON +// for the variance, while an expected result in the format of 0.0xxxxxxxxx will use +// PAL_EPSILON / 10 and and expected result in the format of x.xxxxxx will use PAL_EPSILON * 10. +#define PAL_EPSILON 4.76837158e-07 + +#define PAL_NAN sqrtf(-1.0f) +#define PAL_POSINF -logf(0.0f) +#define PAL_NEGINF logf(0.0f) + +/** + * 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 = cbrtf(value); + + /* + * The test is valid when the difference between result + * and expected is less than or equal to variance + */ + float delta = fabsf(result - expected); + + if (delta > variance) + { + Fail("cbrtf(%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 = cbrtf(value); + + if (!_isnanf(result)) + { + Fail("cbrtf(%g) returned %10.9g when it should have returned %10.9g", + value, result, PAL_NAN); + } +} + +int __cdecl main(int argc, char **argv) +{ + struct test tests[] = + { + /* value expected variance */ + { 0.318309886f, 0.682784063f, PAL_EPSILON }, // value: 1 / pi + { 0.434294482f, 0.757288631f, PAL_EPSILON }, // value: log10f(e) + { 0.636619772f, 0.860254014f, PAL_EPSILON }, // value: 2 / pi + { 0.693147181f, 0.884997045f, PAL_EPSILON }, // value: ln(2) + { 0.707106781f, 0.890898718f, PAL_EPSILON }, // value: 1 / sqrtf(2) + { 0.785398163f, 0.922635074f, PAL_EPSILON }, // value: pi / 4 + { 1, 1, PAL_EPSILON * 10 }, + { 1.12837917f, 1.04108220f, PAL_EPSILON * 10 }, // value: 2 / sqrtf(pi) + { 1.41421356f, 1.12246205f, PAL_EPSILON * 10 }, // value: sqrtf(2) + { 1.44269504f, 1.12994728f, PAL_EPSILON * 10 }, // value: logf2(e) + { 1.57079633f, 1.16244735f, PAL_EPSILON * 10 }, // value: pi / 2 + { 2.30258509f, 1.32050048f, PAL_EPSILON * 10 }, // value: ln(10) + { 2.71828183f, 1.39561243f, PAL_EPSILON * 10 }, // value: e + { 3.14159265f, 1.46459189f, PAL_EPSILON * 10 }, // value: pi + }; + + /* PAL initialization */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + validate(-0.0f, -0.0f, PAL_EPSILON); + validate( 0.0f, 0.0f, PAL_EPSILON); + + 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(PAL_NAN); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/cbrtf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/cbrtf/test1/testinfo.dat new file mode 100644 index 0000000000..e42cf2659f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/cbrtf/test1/testinfo.dat @@ -0,0 +1,17 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = cbrtf +Name = Call cbrtf on positive values and zero. +TYPE = DEFAULT +EXE1 = test1 +Description += Call the cbrtf function on a positive value, a positive value += with a decimal and on the maxium possible float value. + + + + diff --git a/src/pal/tests/palsuite/paltestlist.txt b/src/pal/tests/palsuite/paltestlist.txt index ea088d75a2..43998d0e83 100644 --- a/src/pal/tests/palsuite/paltestlist.txt +++ b/src/pal/tests/palsuite/paltestlist.txt @@ -1,17 +1,25 @@ 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/atan2/test1/paltest_atan2_test1 c_runtime/atan2f/test1/paltest_atan2f_test1 c_runtime/atanf/test1/paltest_atanf_test1 +c_runtime/atanh/test1/paltest_atanh_test1 +c_runtime/atanhf/test1/paltest_atanhf_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/cbrt/test1/paltest_cbrt_test1 +c_runtime/cbrtf/test1/paltest_cbrtf_test1 c_runtime/ceil/test1/paltest_ceil_test1 c_runtime/ceilf/test1/paltest_ceilf_test1 c_runtime/cos/test1/paltest_cos_test1 diff --git a/src/pal/tests/palsuite/palverify.dat b/src/pal/tests/palsuite/palverify.dat index 3d711c1895..697a080f5a 100644 --- a/src/pal/tests/palsuite/palverify.dat +++ b/src/pal/tests/palsuite/palverify.dat @@ -116,17 +116,25 @@ 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/atan2/test1,1 c_runtime/atan2f/test1,1 c_runtime/atanf/test1,1 +c_runtime/atanh/test1,1 +c_runtime/atanhf/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/cbrt/test1,1 +c_runtime/cbrtf/test1,1 c_runtime/ceil/test1,1 c_runtime/ceilf/test1,1 c_runtime/cos/test1,1 -- cgit v1.2.3