-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before this was generating an error, because there was no object `nan` inside the `dace::math` namespace. This commit adds a `nan` object to the namespace, the implementation is based on `typeless_pi`.
- Loading branch information
1 parent
b6e1c9d
commit ae378e1
Showing
2 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2019-2021 ETH Zurich and the DaCe authors. All rights reserved. | ||
#ifndef __DACE_NAN_H | ||
#define __DACE_NAN_H | ||
|
||
// Class to define a stateless NAN and related operators. | ||
#include <limits> | ||
|
||
namespace dace | ||
{ | ||
namespace math | ||
{ | ||
////////////////////////////////////////////////////// | ||
// Defines a typeless Pi | ||
struct typeless_nan | ||
{ | ||
operator int() const = delete; | ||
operator float() const | ||
{ | ||
return std::numeric_limits<float>::quiet_NaN(); | ||
} | ||
operator double() const | ||
{ | ||
return std::numeric_limits<double>::quiet_NaN(); | ||
} | ||
operator long double() const | ||
{ | ||
return std::numeric_limits<long double>::quiet_NaN(); | ||
} | ||
typeless_nan operator+() const | ||
{ | ||
return typeless_nan{}; | ||
} | ||
typeless_nan operator-() const | ||
{ | ||
return typeless_nan{}; | ||
} | ||
}; | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator*(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator*(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator*(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator+(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator+(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator+(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator-(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator-(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator-(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator/(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator/(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator/(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator%(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator%(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator%(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
} | ||
} | ||
|
||
//These functions allows to perfrom operations with `typeless_nan` instances. | ||
# define FADAPT(F) DACE_CONSTEXPR ::dace::math::typeless_nan F (::dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; } | ||
# define FADAPT2(F) template<typename T1> DACE_CONSTEXPR dace::math::typeless_nan F (T1&&, dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; }; \ | ||
template<typename T2> DACE_CONSTEXPR dace::math::typeless_nan F (dace::math::typeless_nan, T2&&) { return ::dace::math::typeless_nan{}; }; \ | ||
DACE_CONSTEXPR ::dace::math::typeless_nan F (dace::math::typeless_nan, dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; } | ||
FADAPT(tanh); FADAPT(cos); FADAPT(sin); FADAPT(sqrt); FADAPT(tan); | ||
FADAPT(acos); FADAPT(asin); FADAPT(atan); FADAPT(log); FADAPT(exp); | ||
FADAPT(floor); FADAPT(ceil); FADAPT(round); FADAPT(abs); | ||
FADAPT2(max); FADAPT2(min); | ||
# undef FADAPT2 | ||
# undef FADAPT | ||
|
||
#endif // __DACE_NAN_H |