constexpr isunordered (#745)

This commit is contained in:
Matt Borland 2022-01-21 18:07:07 +02:00 committed by GitHub
parent be7b305ad5
commit 50008bb6ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 102 additions and 0 deletions

View File

@ -179,6 +179,9 @@ All of the following functions require C++17 or greater.
template <typename Arithmetic1, typename Arithmetic2 = Arithmetic1>
inline constexpr bool islessequal(Arithmetic1 x, Arithmetic2 y) noexcept
template <typename T>
inline constexpr bool isunordered(T x, T y) noexcept
} // Namespaces
[endsect] [/section:ccmath Constexpr CMath]

View File

@ -37,5 +37,6 @@
#include <boost/math/ccmath/isgreaterequal.hpp>
#include <boost/math/ccmath/isless.hpp>
#include <boost/math/ccmath/islessequal.hpp>
#include <boost/math/ccmath/isunordered.hpp>
#endif // BOOST_MATH_CCMATH_HPP

View File

@ -0,0 +1,31 @@
// (C) Copyright Matt Borland 2022.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_MATH_CCMATH_ISUNORDERED_HPP
#define BOOST_MATH_CCMATH_ISUNORDERED_HPP
#include <cmath>
#include <boost/math/tools/is_constant_evaluated.hpp>
#include <boost/math/ccmath/isnan.hpp>
namespace boost::math::ccmath {
template <typename T>
inline constexpr bool isunordered(const T x, const T y) noexcept
{
if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))
{
return boost::math::ccmath::isnan(x) || boost::math::ccmath::isnan(y);
}
else
{
using std::isunordered;
return isunordered(x, y);
}
}
} // Namespaces
#endif // BOOST_MATH_CCMATH_ISUNORDERED_HPP

View File

@ -151,6 +151,7 @@ test-suite special_fun :
[ run ccmath_isgreaterequal_test.cpp ../../test/build//boost_unit_test_framework : : : [ requires cxx17_if_constexpr ] ]
[ run ccmath_isless_test.cpp ../../test/build//boost_unit_test_framework : : : [ requires cxx17_if_constexpr ] ]
[ run ccmath_islessequal_test.cpp ../../test/build//boost_unit_test_framework : : : [ requires cxx17_if_constexpr ] ]
[ run ccmath_isunordered_test.cpp ../../test/build//boost_unit_test_framework : : : [ requires cxx17_if_constexpr ] ]
[ run log1p_expm1_test.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ]
[ run powm1_sqrtp1m1_test.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ]
[ run git_issue_705.cpp ../../test/build//boost_unit_test_framework ]

View File

@ -0,0 +1,50 @@
// (C) Copyright Matt Borland 2022.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <cmath>
#include <cfloat>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <boost/math/ccmath/isunordered.hpp>
#ifdef BOOST_HAS_FLOAT128
#include <boost/multiprecision/float128.hpp>
#endif
template <typename T>
constexpr void test()
{
static_assert(boost::math::ccmath::isunordered(std::numeric_limits<T>::quiet_NaN(), T(0)));
static_assert(boost::math::ccmath::isunordered(T(0), std::numeric_limits<T>::quiet_NaN()));
static_assert(boost::math::ccmath::isunordered(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::quiet_NaN()));
static_assert(!boost::math::ccmath::isunordered(T(0), std::numeric_limits<T>::infinity()));
static_assert(!boost::math::ccmath::isunordered(std::numeric_limits<T>::infinity(), T(0)));
static_assert(!boost::math::ccmath::isunordered(T(1), T(2)));
}
#if !defined(BOOST_MATH_NO_CONSTEXPR_DETECTION) && !defined(BOOST_MATH_USING_BUILTIN_CONSTANT_P)
int main()
{
test<float>();
test<double>();
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
test<long double>();
#endif
#ifdef BOOST_HAS_FLOAT128
test<boost::multiprecision::float128>();
#endif
return 0;
}
#else
int main()
{
return 0;
}
#endif

View File

@ -0,0 +1,16 @@
// (C) Copyright Matt Borland 2022.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/math/ccmath/isunordered.hpp>
#include "test_compile_result.hpp"
void compile_and_link_test()
{
check_result<float>(boost::math::ccmath::isunordered(1.0f, 1.0f));
check_result<double>(boost::math::ccmath::isunordered(1.0, 1.0));
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
check_result<long double>(boost::math::ccmath::isunordered(1.0l, 1.0l));
#endif
}