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
9 #ifndef _LIBCPP___MATH_EXPONENTIAL_FUNCTIONS_H
10 #define _LIBCPP___MATH_EXPONENTIAL_FUNCTIONS_H
11
12 #include <__config>
13 #include <__type_traits/enable_if.h>
14 #include <__type_traits/is_arithmetic.h>
15 #include <__type_traits/is_integral.h>
16 #include <__type_traits/is_same.h>
17 #include <__type_traits/promote.h>
18
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 # pragma GCC system_header
21 #endif
22
23 _LIBCPP_BEGIN_NAMESPACE_STD
24
25 namespace __math {
26
27 // exp
28
exp(float __x)29 inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT { return __builtin_expf(__x); }
30
31 template <class = int>
exp(double __x)32 _LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT {
33 return __builtin_exp(__x);
34 }
35
exp(long double __x)36 inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT { return __builtin_expl(__x); }
37
38 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
exp(_A1 __x)39 inline _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) _NOEXCEPT {
40 return __builtin_exp((double)__x);
41 }
42
43 // frexp
44
frexp(float __x,int * __e)45 inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT { return __builtin_frexpf(__x, __e); }
46
47 template <class = int>
frexp(double __x,int * __e)48 _LIBCPP_HIDE_FROM_ABI double frexp(double __x, int* __e) _NOEXCEPT {
49 return __builtin_frexp(__x, __e);
50 }
51
frexp(long double __x,int * __e)52 inline _LIBCPP_HIDE_FROM_ABI long double frexp(long double __x, int* __e) _NOEXCEPT {
53 return __builtin_frexpl(__x, __e);
54 }
55
56 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
frexp(_A1 __x,int * __e)57 inline _LIBCPP_HIDE_FROM_ABI double frexp(_A1 __x, int* __e) _NOEXCEPT {
58 return __builtin_frexp((double)__x, __e);
59 }
60
61 // ldexp
62
ldexp(float __x,int __e)63 inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT { return __builtin_ldexpf(__x, __e); }
64
65 template <class = int>
ldexp(double __x,int __e)66 _LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __e) _NOEXCEPT {
67 return __builtin_ldexp(__x, __e);
68 }
69
ldexp(long double __x,int __e)70 inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __e) _NOEXCEPT {
71 return __builtin_ldexpl(__x, __e);
72 }
73
74 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
ldexp(_A1 __x,int __e)75 inline _LIBCPP_HIDE_FROM_ABI double ldexp(_A1 __x, int __e) _NOEXCEPT {
76 return __builtin_ldexp((double)__x, __e);
77 }
78
79 // exp2
80
exp2(float __x)81 inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT { return __builtin_exp2f(__x); }
82
83 template <class = int>
exp2(double __x)84 _LIBCPP_HIDE_FROM_ABI double exp2(double __x) _NOEXCEPT {
85 return __builtin_exp2(__x);
86 }
87
exp2(long double __x)88 inline _LIBCPP_HIDE_FROM_ABI long double exp2(long double __x) _NOEXCEPT { return __builtin_exp2l(__x); }
89
90 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
exp2(_A1 __x)91 inline _LIBCPP_HIDE_FROM_ABI double exp2(_A1 __x) _NOEXCEPT {
92 return __builtin_exp2((double)__x);
93 }
94
95 // expm1
96
expm1(float __x)97 inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT { return __builtin_expm1f(__x); }
98
99 template <class = int>
expm1(double __x)100 _LIBCPP_HIDE_FROM_ABI double expm1(double __x) _NOEXCEPT {
101 return __builtin_expm1(__x);
102 }
103
expm1(long double __x)104 inline _LIBCPP_HIDE_FROM_ABI long double expm1(long double __x) _NOEXCEPT { return __builtin_expm1l(__x); }
105
106 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
expm1(_A1 __x)107 inline _LIBCPP_HIDE_FROM_ABI double expm1(_A1 __x) _NOEXCEPT {
108 return __builtin_expm1((double)__x);
109 }
110
111 // scalbln
112
scalbln(float __x,long __y)113 inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT { return __builtin_scalblnf(__x, __y); }
114
115 template <class = int>
scalbln(double __x,long __y)116 _LIBCPP_HIDE_FROM_ABI double scalbln(double __x, long __y) _NOEXCEPT {
117 return __builtin_scalbln(__x, __y);
118 }
119
scalbln(long double __x,long __y)120 inline _LIBCPP_HIDE_FROM_ABI long double scalbln(long double __x, long __y) _NOEXCEPT {
121 return __builtin_scalblnl(__x, __y);
122 }
123
124 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
scalbln(_A1 __x,long __y)125 inline _LIBCPP_HIDE_FROM_ABI double scalbln(_A1 __x, long __y) _NOEXCEPT {
126 return __builtin_scalbln((double)__x, __y);
127 }
128
129 // scalbn
130
scalbn(float __x,int __y)131 inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT { return __builtin_scalbnf(__x, __y); }
132
133 template <class = int>
scalbn(double __x,int __y)134 _LIBCPP_HIDE_FROM_ABI double scalbn(double __x, int __y) _NOEXCEPT {
135 return __builtin_scalbn(__x, __y);
136 }
137
scalbn(long double __x,int __y)138 inline _LIBCPP_HIDE_FROM_ABI long double scalbn(long double __x, int __y) _NOEXCEPT {
139 return __builtin_scalbnl(__x, __y);
140 }
141
142 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
scalbn(_A1 __x,int __y)143 inline _LIBCPP_HIDE_FROM_ABI double scalbn(_A1 __x, int __y) _NOEXCEPT {
144 return __builtin_scalbn((double)__x, __y);
145 }
146
147 // pow
148
pow(float __x,float __y)149 inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT { return __builtin_powf(__x, __y); }
150
151 template <class = int>
pow(double __x,double __y)152 _LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT {
153 return __builtin_pow(__x, __y);
154 }
155
pow(long double __x,long double __y)156 inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT {
157 return __builtin_powl(__x, __y);
158 }
159
160 template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
pow(_A1 __x,_A2 __y)161 inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type pow(_A1 __x, _A2 __y) _NOEXCEPT {
162 using __result_type = typename __promote<_A1, _A2>::type;
163 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
164 return __math::pow((__result_type)__x, (__result_type)__y);
165 }
166
167 } // namespace __math
168
169 _LIBCPP_END_NAMESPACE_STD
170
171 #endif // _LIBCPP___MATH_EXPONENTIAL_FUNCTIONS_H
172