Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/__cmath/arithmetic.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_ARITHMETIC_H | |||||
#define _LIBCPP___CMATH_ARITHMETIC_H | |||||
#include <__config> | |||||
#include <__type_traits/enable_if.h> | |||||
#include <__type_traits/is_arithmetic.h> | |||||
#include <__type_traits/is_integral.h> | |||||
#include <__type_traits/promote.h> | |||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | |||||
# pragma GCC system_header | |||||
#endif | |||||
_LIBCPP_BEGIN_NAMESPACE_STD | |||||
inline _LIBCPP_HIDE_FROM_ABI float exp(float __v) _NOEXCEPT { return __builtin_expf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double exp(double __v) _NOEXCEPT { | |||||
return __builtin_exp(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __v) _NOEXCEPT { return __builtin_expl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double exp(_Tp __v) _NOEXCEPT { | |||||
return __builtin_exp(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT { return __builtin_fmodf(__x, __y); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double fmod(double __x, double __y) _NOEXCEPT { | |||||
return __builtin_fmod(__x, __y); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y) _NOEXCEPT { | |||||
return __builtin_fmodl(__x, __y); | |||||
} | |||||
template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_arithmetic<_Up>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI typename __promote<_Tp, _Up>::type fmod(_Tp __x, _Up __y) _NOEXCEPT { | |||||
using __result_type = typename __promote<_Tp, _Up>::type; | |||||
return std::fmod(static_cast<__result_type>(__x), static_cast<__result_type>(__y)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __exp) _NOEXCEPT { return __builtin_ldexpf(__x, __exp); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __exp) _NOEXCEPT { | |||||
return __builtin_ldexp(__x, __exp); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __exp) _NOEXCEPT { | |||||
return __builtin_ldexpl(__x, __exp); | |||||
} | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double ldexp(_Tp __x, int __exp) _NOEXCEPT { | |||||
return __builtin_ldexp(static_cast<double>(__x), __exp); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT { return __builtin_powf(__x, __y); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT { | |||||
return __builtin_pow(__x, __y); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT { | |||||
return __builtin_powl(__x, __y); | |||||
} | |||||
template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_arithmetic<_Up>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI typename __promote<_Tp, _Up>::type pow(_Tp __x, _Up __y) _NOEXCEPT { | |||||
using __result_type = typename __promote<_Tp, _Up>::type; | |||||
return std::pow(static_cast<__result_type>(__x), static_cast<__result_type>(__y)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT { return __builtin_sqrtf(__x); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double sqrt(double __x) _NOEXCEPT { | |||||
return __builtin_sqrt(__x); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT { return __builtin_sqrtl(__x); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double sqrt(_Tp __v) _NOEXCEPT { | |||||
return __builtin_sqrt(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT { | |||||
return __builtin_cbrt(__x); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT { return __builtin_cbrtl(__x); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double cbrt(_Tp __v) _NOEXCEPT { | |||||
return __builtin_cbrt(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float exp2(float __v) _NOEXCEPT { return __builtin_exp2f(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double exp2(double __v) _NOEXCEPT { | |||||
return __builtin_exp2(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __v) _NOEXCEPT { return __builtin_exp2l(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double exp2(_Tp __v) _NOEXCEPT { | |||||
return __builtin_exp2(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float expm1(float __v) _NOEXCEPT { return __builtin_expm1f(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double expm1(double __v) _NOEXCEPT { | |||||
return __builtin_expm1(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __v) _NOEXCEPT { return __builtin_expm1l(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double expm1(_Tp __v) _NOEXCEPT { | |||||
return __builtin_expm1(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float erf(float __v) _NOEXCEPT { return __builtin_erff(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double erf(double __v) _NOEXCEPT { | |||||
return __builtin_erf(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double erf(long double __v) _NOEXCEPT { return __builtin_erfl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double erf(_Tp __v) _NOEXCEPT { | |||||
return __builtin_erf(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float erfc(float __v) _NOEXCEPT { return __builtin_erfcf(__v); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double erfc(double __v) _NOEXCEPT { | |||||
return __builtin_erfc(__v); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double erfc(long double __v) _NOEXCEPT { return __builtin_erfcl(__v); } | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double erfc(_Tp __v) { | |||||
return __builtin_erfc(static_cast<double>(__v)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT { | |||||
return __builtin_fmaf(__x, __y, __z); | |||||
} | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double fma(double __x, double __y, double __z) _NOEXCEPT { | |||||
return __builtin_fma(__x, __y, __z); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double fma(long double __x, long double __y, long double __z) _NOEXCEPT { | |||||
return __builtin_fmal(__x, __y, __z); | |||||
} | |||||
template <class _T1, | |||||
class _T2, | |||||
class _T3, | |||||
__enable_if_t<is_arithmetic<_T1>::value && is_arithmetic<_T2>::value && is_arithmetic<_T3>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI typename __promote<_T1, _T2, _T3>::type fma(_T1 __x, _T2 __y, _T3 __z) _NOEXCEPT { | |||||
using __result_type = typename __promote<_T1, _T2, _T3>::type; | |||||
return std::fma(static_cast<__result_type>(__x), static_cast<__result_type>(__y), static_cast<__result_type>(__z)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT { return __builtin_hypotf(__x, __y); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double hypot(double __x, double __y) _NOEXCEPT { | |||||
return __builtin_hypot(__x, __y); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double hypot(long double __x, long double __y) _NOEXCEPT { | |||||
return __builtin_hypotl(__x, __y); | |||||
} | |||||
template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_arithmetic<_Up>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI typename __promote<_Tp, _Up>::type hypot(_Tp __x, _Up __y) _NOEXCEPT { | |||||
using __result_type = typename __promote<_Tp, _Up>::type; | |||||
return std::hypot(static_cast<__result_type>(__x), static_cast<__result_type>(__y)); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __exp) _NOEXCEPT { return __builtin_scalblnf(__x, __exp); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __exp) _NOEXCEPT { | |||||
return __builtin_scalbln(__x, __exp); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double scalbln(long double __x, long __exp) _NOEXCEPT { | |||||
return __builtin_scalblnl(__x, __exp); | |||||
} | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double scalbln(_Tp __v, long __exp) _NOEXCEPT { | |||||
return __builtin_scalbln(static_cast<double>(__v), __exp); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __exp) _NOEXCEPT { return __builtin_scalbnf(__x, __exp); } | |||||
template <class = int> | |||||
_LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __exp) _NOEXCEPT { | |||||
return __builtin_scalbn(__x, __exp); | |||||
} | |||||
inline _LIBCPP_HIDE_FROM_ABI long double scalbn(long double __x, int __exp) _NOEXCEPT { | |||||
return __builtin_scalbnl(__x, __exp); | |||||
} | |||||
template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0> | |||||
_LIBCPP_HIDE_FROM_ABI double scalbn(_Tp __x, int __exp) _NOEXCEPT { | |||||
return __builtin_scalbn(static_cast<double>(__x), __exp); | |||||
} | |||||
_LIBCPP_END_NAMESPACE_STD | |||||
using std::cbrt; | |||||
using std::erf; | |||||
using std::erfc; | |||||
using std::exp; | |||||
using std::exp2; | |||||
using std::expm1; | |||||
using std::fma; | |||||
using std::fmod; | |||||
using std::hypot; | |||||
using std::ldexp; | |||||
using std::pow; | |||||
using std::scalbln; | |||||
using std::scalbn; | |||||
using std::sqrt; | |||||
#endif // _LIBCPP___CMATH_ARITHMETIC_H |