Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variadic template support to min, max, any/all_finite/nan/inf functions and moved them out of the 'internal' namespace. #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 46 additions & 16 deletions include/gcem_incl/is_finite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
#ifndef _gcem_is_finite_HPP
#define _gcem_is_finite_HPP

namespace internal
{
/**
* Compile-time check if a float is not NaN-valued or +/-Inf
*
* @param x floating point value.
* @return true if \c x is not NaN-valued or +/-Inf, false otherwise.
*/

template<typename T>
constexpr
Expand All @@ -37,42 +41,68 @@ noexcept
return (!is_nan(x)) && (!is_inf(x));
}

template<typename T1, typename T2>
/**
* Compile-time check if a float is not NaN-valued or +/-Inf
*
* @param x floating point value.
* @return true if \c x is not NaN-valued or +/-Inf, false otherwise.
*/

template<typename T>
constexpr
bool
any_finite(const T1 x, const T2 y)
any_finite(const T x)
noexcept
{
return( is_finite(x) || is_finite(y) );
return is_finite(x);
}

template<typename T1, typename T2>
/**
* Compile-time check if any float in a sequence is not NaN-valued or +/-Inf
*
* @param args... floating point values.
* @return true if any float in a sequence is not NaN-valued or +/-Inf, false otherwise.
*/

template<typename T, typename... Args>
constexpr
bool
all_finite(const T1 x, const T2 y)
any_finite(const T x, const Args... args)
noexcept
{
return( is_finite(x) && is_finite(y) );
return is_finite(x) || any_finite(args...);
}

template<typename T1, typename T2, typename T3>
/**
* Compile-time check if a float is not NaN-valued or +/-Inf
*
* @param x floating point value.
* @return true if \c x is not NaN-valued or +/-Inf, false otherwise.
*/

template<typename T>
constexpr
bool
any_finite(const T1 x, const T2 y, const T3 z)
all_finite(const T x)
noexcept
{
return( is_finite(x) || is_finite(y) || is_finite(z) );
return is_finite(x);
}

template<typename T1, typename T2, typename T3>
/**
* Compile-time check if all floats in a sequence are not NaN-valued or +/-Inf
*
* @param args... floating point values.
* @return true if all floats in a sequence are not NaN-valued or +/-Inf, false otherwise.
*/

template<typename T, typename... Args>
constexpr
bool
all_finite(const T1 x, const T2 y, const T3 z)
all_finite(const T x, const Args... args)
noexcept
{
return( is_finite(x) && is_finite(y) && is_finite(z) );
}

return is_finite(x) && all_finite(args...);
}

#endif
183 changes: 142 additions & 41 deletions include/gcem_incl/is_inf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
#ifndef _gcem_is_inf_HPP
#define _gcem_is_inf_HPP

namespace internal
{
/**
* Compile-time check if a float is -Inf
*
* @param x floating point value.
* @return true if \c x is -Inf, false otherwise.
*/

template<typename T>
constexpr
Expand All @@ -37,44 +41,79 @@ noexcept
return x == - GCLIM<T>::infinity();
}

template<typename T1, typename T2>
/**
* Compile-time check if a float is -Inf
*
* @param x floating point value.
* @return true if \c x is -Inf, false otherwise.
*/

template<typename T>
constexpr
bool
any_neginf(const T1 x, const T2 y)
any_neginf(const T x)
noexcept
{
return( is_neginf(x) || is_neginf(y) );
return is_neginf(x);
}

template<typename T1, typename T2>
/**
* Compile-time check if any float in a sequence is -Inf
*
* @param args... floating point values.
* @return true if any float in a sequence is -Inf, false otherwise.
*/

template<typename T, typename... Args>
constexpr
bool
all_neginf(const T1 x, const T2 y)
any_neginf(const T x, const Args... args)
noexcept
{
return( is_neginf(x) && is_neginf(y) );
return is_neginf(x) || is_neginf(args...);
}

template<typename T1, typename T2, typename T3>
/**
* Compile-time check if a float is -Inf
*
* @param x floating point value.
* @return true if \c x is -Inf, false otherwise.
*/

template<typename T>
constexpr
bool
any_neginf(const T1 x, const T2 y, const T3 z)
all_neginf(const T x)
noexcept
{
return( is_neginf(x) || is_neginf(y) || is_neginf(z) );
return is_neginf(x);
}

template<typename T1, typename T2, typename T3>
/**
* Compile-time check if all floats in a sequence are -Inf
*
* @param args... floating point values.
* @return true if all floats in a sequence are -Inf, false otherwise.
*/

template<typename T, typename... Args>
constexpr
bool
all_neginf(const T1 x, const T2 y, const T3 z)
all_neginf(const T x, const Args... args)
noexcept
{
return( is_neginf(x) && is_neginf(y) && is_neginf(z) );
return is_neginf(x) && all_neginf(args...);
}

//

/**
* Compile-time check if a float is +Inf
*
* @param x floating point value.
* @return true if \c x is +Inf, false otherwise.
*/

template<typename T>
constexpr
bool
Expand All @@ -84,89 +123,151 @@ noexcept
return x == GCLIM<T>::infinity();
}

template<typename T1, typename T2>
/**
* Compile-time check if a float is +Inf
*
* @param x floating point value.
* @return true if \c x is +Inf, false otherwise.
*/

template<typename T>
constexpr
bool
any_posinf(const T1 x, const T2 y)
any_posinf(const T x)
noexcept
{
return( is_posinf(x) || is_posinf(y) );
return is_posinf(x);
}

template<typename T1, typename T2>
/**
* Compile-time check if any float in a sequence is +Inf
*
* @param args... floating point values.
* @return true if any float in a sequence is +Inf, false otherwise.
*/

template<typename T, typename... Args>
constexpr
bool
all_posinf(const T1 x, const T2 y)
any_posinf(const T x, const Args... args)
noexcept
{
return( is_posinf(x) && is_posinf(y) );
return is_posinf(x) || any_posinf(args...);
}

template<typename T1, typename T2, typename T3>
/**
* Compile-time check if a float is +Inf
*
* @param x floating point value.
* @return true if \c x is +Inf, false otherwise.
*/

template<typename T>
constexpr
bool
any_posinf(const T1 x, const T2 y, const T3 z)
all_posinf(const T x)
noexcept
{
return( is_posinf(x) || is_posinf(y) || is_posinf(z) );
return is_posinf(x);
}

template<typename T1, typename T2, typename T3>
/**
* Compile-time check if all floats in a sequence are +Inf
*
* @param args... floating point values.
* @return true if all floats in a sequence are +Inf, false otherwise.
*/


template<typename T, typename... Args>
constexpr
bool
all_posinf(const T1 x, const T2 y, const T3 z)
all_posinf(const T x, const Args... args)
noexcept
{
return( is_posinf(x) && is_posinf(y) && is_posinf(z) );
return is_posinf(x) && all_posinf(args...);
}

//

/**
* Compile-time check if a float is +/-Inf
*
* @param x floating point value.
* @return true if \c x is +/-Inf, false otherwise.
*/

template<typename T>
constexpr
bool
is_inf(const T x)
noexcept
{
return( is_neginf(x) || is_posinf(x) );
return is_neginf(x) || is_posinf(x);
}

template<typename T1, typename T2>
/**
* Compile-time check if a float is +/-Inf
*
* @param x floating point value.
* @return true if \c x is +/-Inf, false otherwise.
*/

template<typename T>
constexpr
bool
any_inf(const T1 x, const T2 y)
any_inf(const T x)
noexcept
{
return( is_inf(x) || is_inf(y) );
return is_inf(x);
}

template<typename T1, typename T2>
/**
* Compile-time check if any float in a sequence is +/-Inf
*
* @param args... floating point values.
* @return true if any float in a sequence is +/-Inf, false otherwise.
*/

template<typename T, typename... Args>
constexpr
bool
all_inf(const T1 x, const T2 y)
any_inf(const T x, const Args... args)
noexcept
{
return( is_inf(x) && is_inf(y) );
return is_inf(x) || any_inf(args...);
}

template<typename T1, typename T2, typename T3>
/**
* Compile-time check if a float is +/-Inf
*
* @param x floating point value.
* @return true if \c x is +/-Inf, false otherwise.
*/

template<typename T>
constexpr
bool
any_inf(const T1 x, const T2 y, const T3 z)
all_inf(const T x)
noexcept
{
return( is_inf(x) || is_inf(y) || is_inf(z) );
return is_inf(x);
}

template<typename T1, typename T2, typename T3>
/**
* Compile-time check if all floats in a sequence are +/-Inf
*
* @param args... floating point values.
* @return true if all floats in a sequence are +/-Inf, false otherwise.
*/

template<typename T, typename... Args>
constexpr
bool
all_inf(const T1 x, const T2 y, const T3 z)
all_inf(const T x, const Args... args)
noexcept
{
return( is_inf(x) && is_inf(y) && is_inf(z) );
}

return is_inf(x) && all_inf(args...);
}

#endif
Loading