forked from alpaka-group/alpaka3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisSpecialIEEE.cpp
More file actions
46 lines (36 loc) · 1.43 KB
/
isSpecialIEEE.cpp
File metadata and controls
46 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Copyright 2025 René Widera, Mehmet Yusufoglu, Andrea Bocci
* SPDX-License-Identifier: MPL-2.0
*/
#include "alpaka/api/generic.hpp"
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <limits>
template<typename T>
static void verifyIsSpecial()
{
namespace generic_math = alpaka::internal::generic::math;
auto const quietNaN = std::numeric_limits<T>::quiet_NaN();
auto const posInf = std::numeric_limits<T>::infinity();
auto const negInf = -posInf;
auto const finiteVal = static_cast<T>(42.5);
CHECK(generic_math::isnan(quietNaN));
CHECK_FALSE(generic_math::isnan(finiteVal));
if constexpr(std::numeric_limits<T>::has_signaling_NaN)
{
auto const signalingNaN = std::numeric_limits<T>::signaling_NaN();
CHECK(generic_math::isnan(signalingNaN));
}
CHECK(generic_math::isinf(posInf));
CHECK(generic_math::isinf(negInf));
CHECK_FALSE(generic_math::isinf(finiteVal));
CHECK(generic_math::isfinite(finiteVal));
CHECK(generic_math::isfinite(static_cast<T>(0)));
CHECK_FALSE(generic_math::isfinite(posInf));
CHECK_FALSE(generic_math::isfinite(negInf));
CHECK_FALSE(generic_math::isfinite(quietNaN));
}
// Regression guard to ensure ieee helper stays stable for each floating type.
TEMPLATE_TEST_CASE("generic ieee helpers detect special values", "[math][generic][ieee]", float, double)
{
verifyIsSpecial<TestType>();
}