Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/__cmath/signbit.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_SIGNBIT_H | |||||
#define _LIBCPP___CMATH_SIGNBIT_H | |||||
#include <__config> | |||||
#include <__type_traits/enable_if.h> | |||||
#include <__type_traits/is_floating_point.h> | |||||
#include <__type_traits/is_integral.h> | |||||
#include <__type_traits/is_signed.h> | |||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | |||||
# pragma GCC system_header | |||||
#endif | |||||
template <class _Tp, std::__enable_if_t<std::is_floating_point<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool signbit(_Tp __v) _NOEXCEPT { | |||||
return __builtin_signbit(__v); | |||||
} | |||||
template <class _Tp, std::__enable_if_t<std::is_integral<_Tp>::value && std::is_signed<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool signbit(_Tp __v) _NOEXCEPT { | |||||
return __v < 0; | |||||
} | |||||
template <class _Tp, std::__enable_if_t<std::is_integral<_Tp>::value && !std::is_signed<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI bool signbit(_Tp) _NOEXCEPT { | |||||
return false; | |||||
} | |||||
#endif // _LIBCPP___CMATH_SIGNBIT_H |