diff options
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/_isnan/test1')
3 files changed, 150 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt new file mode 100644 index 0000000000..e14d0cc64b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnan/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_isnan_test1 + ${SOURCES} +) + +add_dependencies(paltest_isnan_test1 coreclrpal) + +target_link_libraries(paltest_isnan_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c new file mode 100644 index 0000000000..d793c9b371 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c @@ -0,0 +1,115 @@ +// 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 _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 +** the true value. +** +**==========================================================================*/ + +#include <palsuite.h> + +#define TO_DOUBLE(x) (*((double*)((void*)&x))) +#define TO_I64(x) (*((INT64*)((void*)&x))) + +/* + * NaN: any double with maximum exponent (0x7ff) and non-zero fraction + */ +int __cdecl main(int argc, char *argv[]) +{ + /* + * Initialize the PAL and return FAIL if this fails + */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + /* + * Try some trivial values + */ + if (_isnan(0.0)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 0.0); + } + + if (_isnan(1.23456)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 1.234567); + } + + if (_isnan(42.0)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 42.0); + } + + UINT64 lneginf = UI64(0xfff0000000000000); + UINT64 lposinf = UI64(0x7ff0000000000000); + + double neginf = TO_DOUBLE(lneginf); + double posinf = TO_DOUBLE(lposinf); + + /* + * Try positive and negative infinity + */ + if (_isnan(neginf)) + { + Fail("_isnan() incorrectly identified negative infinity as NaN!\n"); + } + + if (_isnan(posinf)) + { + Fail("_isnan() incorrectly identified infinity as NaN!\n"); + } + + /* + * Try setting the least significant bit of the fraction, + * positive and negative + */ + UINT64 lsnan = UI64(0xfff0000000000001); + double snan = TO_DOUBLE(lsnan); + + if (!_isnan(snan)) + { + Fail("_isnan() failed to identify %I64x as NaN!\n", lsnan); + } + + UINT64 lqnan = UI64(0x7ff0000000000001); + double qnan = TO_DOUBLE(lqnan); + + if (!_isnan(qnan)) + { + Fail("_isnan() failed to identify %I64x as NaN!\n", lqnan); + } + + /* + * Try setting the most significant bit of the fraction, + * positive and negative + */ + lsnan = UI64(0xfff8000000000000); + snan = TO_DOUBLE(lsnan); + + if (!_isnan(snan)) + { + Fail ("_isnan() failed to identify %I64x as NaN!\n", lsnan); + } + + lqnan = UI64(0x7ff8000000000000); + qnan = TO_DOUBLE(lqnan); + + if (!_isnan(qnan)) + { + Fail ("_isnan() failed to identify %I64x as NaN!\n", lqnan); + } + + 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 new file mode 100644 index 0000000000..d5de17e219 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnan/test1/testinfo.dat @@ -0,0 +1,16 @@ +# 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 = _isnan +Name = Test #1 for _isnan +TYPE = DEFAULT +EXE1 = test1 +Description += 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 += the true value. |