diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
commit | db20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch) | |
tree | e5435159cd1bf0519276363a6fe1663d1721bed3 /src/pal/tests/palsuite/c_runtime/_isnanf/test1 | |
parent | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff) | |
download | coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2 coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip |
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/_isnanf/test1')
3 files changed, 150 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/_isnanf/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_isnanf/test1/CMakeLists.txt new file mode 100644 index 0000000000..a8d42aa975 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnanf/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_isnanf_test1 + ${SOURCES} +) + +add_dependencies(paltest_isnanf_test1 coreclrpal) + +target_link_libraries(paltest_isnanf_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_isnanf/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_isnanf/test1/test1.c new file mode 100644 index 0000000000..9b75a7236d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnanf/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 _isnanf 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_FLOAT(x) (*((float*)((void*)&x))) +#define TO_I32(x) (*((INT32*)((void*)&x))) + +/* + * NaN: any float with maximum exponent (0x7f8) 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 (_isnanf(0.0f)) + { + Fail("_isnanf() incorrectly identified %f as NaN!\n", 0.0f); + } + + if (_isnanf(1.234567f)) + { + Fail("_isnanf() incorrectly identified %f as NaN!\n", 1.234567f); + } + + if (_isnanf(42.0f)) + { + Fail("_isnanf() incorrectly identified %f as NaN!\n", 42.0f); + } + + UINT32 lneginf = 0xff800000u; + UINT32 lposinf = 0x7f800000u; + + float neginf = TO_FLOAT(lneginf); + float posinf = TO_FLOAT(lposinf); + + /* + * Try positive and negative infinity + */ + if (_isnanf(neginf)) + { + Fail("_isnanf() incorrectly identified negative infinity as NaN!\n"); + } + + if (_isnanf(posinf)) + { + Fail("_isnanf() incorrectly identified infinity as NaN!\n"); + } + + /* + * Try setting the least significant bit of the fraction, + * positive and negative + */ + UINT32 lsnan = 0xff800001u; + float snan = TO_FLOAT(lsnan); + + if (!_isnanf(snan)) + { + Fail("_isnanf() failed to identify %I32x as NaN!\n", lsnan); + } + + UINT32 lqnan = 0x7f800001u; + float qnan = TO_FLOAT(lqnan); + + if (!_isnanf(qnan)) + { + Fail("_isnanf() failed to identify %I32x as NaN!\n", lqnan); + } + + /* + * Try setting the most significant bit of the fraction, + * positive and negative + */ + lsnan = 0xffc00000u; + snan = TO_FLOAT(lsnan); + + if (!_isnanf(snan)) + { + Fail ("_isnanf() failed to identify %I32x as NaN!\n", lsnan); + } + + lqnan = 0x7fc00000u; + qnan = TO_FLOAT(lqnan); + + if (!_isnanf(qnan)) + { + Fail ("_isnanf() failed to identify %I32x as NaN!\n", lqnan); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_isnanf/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_isnanf/test1/testinfo.dat new file mode 100644 index 0000000000..22b0edbd74 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnanf/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 = _isnanf +Name = Test #1 for _isnanf +TYPE = DEFAULT +EXE1 = test1 +Description += Test _isnanf 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. |