exponential_functions.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___MATH_EXPONENTIAL_FUNCTIONS_H
  9. #define _LIBCPP___MATH_EXPONENTIAL_FUNCTIONS_H
  10. #include <__config>
  11. #include <__type_traits/enable_if.h>
  12. #include <__type_traits/is_arithmetic.h>
  13. #include <__type_traits/is_integral.h>
  14. #include <__type_traits/is_same.h>
  15. #include <__type_traits/promote.h>
  16. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  17. # pragma GCC system_header
  18. #endif
  19. _LIBCPP_BEGIN_NAMESPACE_STD
  20. namespace __math {
  21. // exp
  22. inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT { return __builtin_expf(__x); }
  23. template <class = int>
  24. _LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT {
  25. return __builtin_exp(__x);
  26. }
  27. inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT { return __builtin_expl(__x); }
  28. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  29. inline _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) _NOEXCEPT {
  30. return __builtin_exp((double)__x);
  31. }
  32. // frexp
  33. inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT { return __builtin_frexpf(__x, __e); }
  34. template <class = int>
  35. _LIBCPP_HIDE_FROM_ABI double frexp(double __x, int* __e) _NOEXCEPT {
  36. return __builtin_frexp(__x, __e);
  37. }
  38. inline _LIBCPP_HIDE_FROM_ABI long double frexp(long double __x, int* __e) _NOEXCEPT {
  39. return __builtin_frexpl(__x, __e);
  40. }
  41. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  42. inline _LIBCPP_HIDE_FROM_ABI double frexp(_A1 __x, int* __e) _NOEXCEPT {
  43. return __builtin_frexp((double)__x, __e);
  44. }
  45. // ldexp
  46. inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT { return __builtin_ldexpf(__x, __e); }
  47. template <class = int>
  48. _LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __e) _NOEXCEPT {
  49. return __builtin_ldexp(__x, __e);
  50. }
  51. inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __e) _NOEXCEPT {
  52. return __builtin_ldexpl(__x, __e);
  53. }
  54. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  55. inline _LIBCPP_HIDE_FROM_ABI double ldexp(_A1 __x, int __e) _NOEXCEPT {
  56. return __builtin_ldexp((double)__x, __e);
  57. }
  58. // exp2
  59. inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT { return __builtin_exp2f(__x); }
  60. template <class = int>
  61. _LIBCPP_HIDE_FROM_ABI double exp2(double __x) _NOEXCEPT {
  62. return __builtin_exp2(__x);
  63. }
  64. inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT { return __builtin_exp2l(__x); }
  65. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  66. inline _LIBCPP_HIDE_FROM_ABI double exp2(_A1 __x) _NOEXCEPT {
  67. return __builtin_exp2((double)__x);
  68. }
  69. // expm1
  70. inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT { return __builtin_expm1f(__x); }
  71. template <class = int>
  72. _LIBCPP_HIDE_FROM_ABI double expm1(double __x) _NOEXCEPT {
  73. return __builtin_expm1(__x);
  74. }
  75. inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT { return __builtin_expm1l(__x); }
  76. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  77. inline _LIBCPP_HIDE_FROM_ABI double expm1(_A1 __x) _NOEXCEPT {
  78. return __builtin_expm1((double)__x);
  79. }
  80. // scalbln
  81. inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT { return __builtin_scalblnf(__x, __y); }
  82. template <class = int>
  83. _LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __y) _NOEXCEPT {
  84. return __builtin_scalbln(__x, __y);
  85. }
  86. inline _LIBCPP_HIDE_FROM_ABI long double scalbln(long double __x, long __y) _NOEXCEPT {
  87. return __builtin_scalblnl(__x, __y);
  88. }
  89. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  90. inline _LIBCPP_HIDE_FROM_ABI double scalbln(_A1 __x, long __y) _NOEXCEPT {
  91. return __builtin_scalbln((double)__x, __y);
  92. }
  93. // scalbn
  94. inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT { return __builtin_scalbnf(__x, __y); }
  95. template <class = int>
  96. _LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __y) _NOEXCEPT {
  97. return __builtin_scalbn(__x, __y);
  98. }
  99. inline _LIBCPP_HIDE_FROM_ABI long double scalbn(long double __x, int __y) _NOEXCEPT {
  100. return __builtin_scalbnl(__x, __y);
  101. }
  102. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  103. inline _LIBCPP_HIDE_FROM_ABI double scalbn(_A1 __x, int __y) _NOEXCEPT {
  104. return __builtin_scalbn((double)__x, __y);
  105. }
  106. // pow
  107. inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT { return __builtin_powf(__x, __y); }
  108. template <class = int>
  109. _LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT {
  110. return __builtin_pow(__x, __y);
  111. }
  112. inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT {
  113. return __builtin_powl(__x, __y);
  114. }
  115. template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
  116. inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type pow(_A1 __x, _A2 __y) _NOEXCEPT {
  117. using __result_type = typename __promote<_A1, _A2>::type;
  118. static_assert((!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value)), "");
  119. return __math::pow((__result_type)__x, (__result_type)__y);
  120. }
  121. } // namespace __math
  122. _LIBCPP_END_NAMESPACE_STD
  123. #endif // _LIBCPP___MATH_EXPONENTIAL_FUNCTIONS_H