Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/__cmath/traits.h
- This file was added.
//===----------------------------------------------------------------------===// | |||||
// | |||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||||
// See https://llvm.org/LICENSE.txt for license information. | |||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
#ifndef _LIBCPP___CMATH_TRAITS_H | |||||
#define _LIBCPP___CMATH_TRAITS_H | |||||
#include <__config> | |||||
#include <__type_traits/enable_if.h> | |||||
#include <__type_traits/is_arithmetic.h> | |||||
#include <limits> | |||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | |||||
# pragma GCC system_header | |||||
#endif | |||||
_LIBCPP_BEGIN_NAMESPACE_STD | |||||
// The MSVC runtime provides these functions already as functions, so there is no need to redefine them. | |||||
#ifndef _LIBCPP_MSVCRT | |||||
template <class _Tp, __enable_if_t<is_arithmetic<_Tp>::value && numeric_limits<_Tp>::has_infinity, int> = 0> | |||||
inline _LIBCPP_HIDE_FROM_ABI bool isfinite(_Tp __lcpp_x) _NOEXCEPT { | |||||
return __builtin_isfinite(__lcpp_x); | |||||
} | |||||
template <class _Tp, __enable_if_t<is_arithmetic<_Tp>::value && !numeric_limits<_Tp>::has_infinity, int> = 0> | |||||
inline _LIBCPP_HIDE_FROM_ABI bool isfinite(_Tp) _NOEXCEPT { | |||||
return true; | |||||
} | |||||
template <class _Tp, __enable_if_t<is_arithmetic<_Tp>::value && numeric_limits<_Tp>::has_infinity, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool isinf(_Tp __v) _NOEXCEPT { | |||||
return __builtin_isinf(__v); | |||||
} | |||||
template <class _Tp, __enable_if_t<is_arithmetic<_Tp>::value && !numeric_limits<_Tp>::has_infinity, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool isinf(_Tp) _NOEXCEPT { | |||||
return false; | |||||
} | |||||
template <class _Tp, __enable_if_t<is_floating_point<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool isnan(_Tp __v) _NOEXCEPT { | |||||
return __builtin_isnan(__v); | |||||
} | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool isnan(_Tp) _NOEXCEPT { | |||||
return false; | |||||
} | |||||
template <class _Tp, __enable_if_t<is_floating_point<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool isnormal(_Tp __v) _NOEXCEPT { | |||||
return __builtin_isnormal(__v); | |||||
} | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool isnormal(_Tp __v) _NOEXCEPT { | |||||
return __v != 0; | |||||
} | |||||
#endif // _LIBCPP_MSVCRT | |||||
_LIBCPP_END_NAMESPACE_STD | |||||
#ifndef _LIBCPP_MSVCRT | |||||
using std::isfinite; | |||||
using std::isinf; | |||||
using std::isnan; | |||||
using std::isnormal; | |||||
#endif | |||||
#endif // _LIBCPP___CMATH_TRAITS_H |