54 lines · plain
1// (C) Copyright Matt Borland 2021.2// Use, modification and distribution are subject to the3// Boost Software License, Version 1.0. (See accompanying file4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)5 6#ifndef BOOST_MATH_CCMATH_ISFINITE7#define BOOST_MATH_CCMATH_ISFINITE8 9#include <boost/math/ccmath/detail/config.hpp>10 11#ifdef BOOST_MATH_NO_CCMATH12#error "The header <boost/math/isfinite.hpp> can only be used in C++17 and later."13#endif14 15#include <boost/math/ccmath/isinf.hpp>16#include <boost/math/ccmath/isnan.hpp>17 18namespace boost::math::ccmath {19 20template <typename T>21inline constexpr bool isfinite(T x)22{23 if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))24 {25 // bool isfinite (IntegralType arg) is a set of overloads accepting the arg argument of any integral type26 // equivalent to casting the integral argument arg to double (e.g. static_cast<double>(arg))27 if constexpr (std::is_integral_v<T>)28 {29 return !boost::math::ccmath::isinf(static_cast<double>(x)) && !boost::math::ccmath::isnan(static_cast<double>(x));30 }31 else32 {33 return !boost::math::ccmath::isinf(x) && !boost::math::ccmath::isnan(x);34 }35 }36 else37 {38 using std::isfinite;39 40 if constexpr (!std::is_integral_v<T>)41 {42 return isfinite(x);43 }44 else45 {46 return isfinite(static_cast<double>(x));47 }48 }49}50 51}52 53#endif // BOOST_MATH_CCMATH_ISFINITE54