Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/__cmath/rounding.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_ROUNDING_H | |||||
#define _LIBCPP___CMATH_ROUNDING_H | |||||
#include <__config> | |||||
#include <__type_traits/enable_if.h> | |||||
#include <__type_traits/is_integral.h> | |||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | |||||
# pragma GCC system_header | |||||
#endif | |||||
_LIBCPP_BEGIN_NAMESPACE_STD | |||||
inline _LIBCPP_HIDE_FROM_ABI float ceil(float __v) _NOEXCEPT { return __builtin_ceilf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double ceil(double __v) { | |||||
return __builtin_ceil(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __v) _NOEXCEPT { return __builtin_ceill(__v); } | |||||
template <class _Tp, __enable_if_t<std::is_integral<_Tp>::value, int> = 0> | |||||
inline _LIBCPP_HIDE_FROM_ABI double ceil(_Tp __v) _NOEXCEPT { | |||||
return __builtin_ceil(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float floor(float __v) _NOEXCEPT { return __builtin_floorf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double floor(double __v) _NOEXCEPT { | |||||
return __builtin_ceil(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __v) _NOEXCEPT { return __builtin_floorl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double floor(_Tp __v) _NOEXCEPT { | |||||
return __builtin_floor(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long long llround(float __v) _NOEXCEPT { return __builtin_llroundf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI long long llround(double __v) _NOEXCEPT { | |||||
return __builtin_llround(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __v) _NOEXCEPT { return __builtin_llroundl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI long long llround(_Tp __v) _NOEXCEPT { | |||||
return __builtin_llround(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long lrint(float __v) _NOEXCEPT { return __builtin_lrintf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI long lrint(double __v) _NOEXCEPT { | |||||
return __builtin_lrint(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __v) _NOEXCEPT { return __builtin_lrintl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI long lrint(_Tp __v) _NOEXCEPT { | |||||
return __builtin_lrint(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __v) _NOEXCEPT { return __builtin_llrintf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI long long llrint(double __v) _NOEXCEPT { | |||||
return __builtin_llrint(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __v) _NOEXCEPT { return __builtin_llrintl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI long long llrint(_Tp __v) _NOEXCEPT { | |||||
return __builtin_llrint(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long lround(float __v) _NOEXCEPT { return __builtin_lroundf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI long lround(double __v) _NOEXCEPT { | |||||
return __builtin_lround(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long lround(long double __v) _NOEXCEPT { return __builtin_lroundl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI long lround(_Tp __v) _NOEXCEPT { | |||||
return __builtin_lround(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __v) _NOEXCEPT { return __builtin_nearbyintf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double nearbyint(double __v) _NOEXCEPT { | |||||
return __builtin_nearbyint(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __v) _NOEXCEPT { return __builtin_nearbyintl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double nearbyint(_Tp __v) _NOEXCEPT { | |||||
return __builtin_nearbyint(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float rint(float __v) _NOEXCEPT { return __builtin_rintf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double rint(double __v) _NOEXCEPT { | |||||
return __builtin_rint(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __v) _NOEXCEPT { return __builtin_rintl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double rint(_Tp __v) _NOEXCEPT { | |||||
return __builtin_rint(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float round(float __v) _NOEXCEPT { return __builtin_roundf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double round(double __v) _NOEXCEPT { | |||||
return __builtin_round(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double round(long double __v) _NOEXCEPT { return __builtin_roundl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double round(_Tp __v) _NOEXCEPT { | |||||
return __builtin_round(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float trunc(float __v) _NOEXCEPT { return __builtin_truncf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double trunc(double __v) _NOEXCEPT { | |||||
return __builtin_trunc(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __v) _NOEXCEPT { return __builtin_truncl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double trunc(_Tp __v) _NOEXCEPT { | |||||
return __builtin_trunc(static_cast<double>(__v)); | |||||
} | |||||
_LIBCPP_END_NAMESPACE_STD | |||||
using std::ceil; | |||||
using std::floor; | |||||
using std::llrint; | |||||
using std::llround; | |||||
using std::lrint; | |||||
using std::lround; | |||||
using std::nearbyint; | |||||
using std::rint; | |||||
using std::round; | |||||
using std::trunc; | |||||
#endif // _LIBCPP___CMATH_ROUNDING_H |