YSTest: cmath.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

cmath.h
浏览该文件的文档.
1 /*
2 © 2014-2016, 2019 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_libdefect_cmath_h_
29 #define YB_INC_libdefect_cmath_h_ 1
30
31 #include <cmath>
32
33 #if defined(__GLIBCXX__) \
34 && (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L) \
35 && !(defined(_GLIBCXX_USE_C99_MATH_TR1))
36
37 extern "C++"
38 {
39
40 namespace std _GLIBCXX_VISIBILITY(default)
41 {
42
43 #ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 #endif
46
47 #undef acosh
48 #undef acoshf
49 #undef acoshl
50 #undef asinh
51 #undef asinhf
52 #undef asinhl
53 #undef atanh
54 #undef atanhf
55 #undef atanhl
56 #undef cbrt
57 #undef cbrtf
58 #undef cbrtl
59 #undef copysign
60 #undef copysignf
61 #undef copysignl
62 #undef erf
63 #undef erff
64 #undef erfl
65 #undef erfc
66 #undef erfcf
67 #undef erfcl
68 #undef exp2
69 #undef exp2f
70 #undef exp2l
71 #undef expm1
72 #undef expm1f
73 #undef expm1l
74 #undef fdim
75 #undef fdimf
76 #undef fdiml
77 #undef fma
78 #undef fmaf
79 #undef fmal
80 #undef fmax
81 #undef fmaxf
82 #undef fmaxl
83 #undef fmin
84 #undef fminf
85 #undef fminl
86 #undef hypot
87 #undef hypotf
88 #undef hypotl
89 #undef ilogb
90 #undef ilogbf
91 #undef ilogbl
92 #undef lgamma
93 #undef lgammaf
94 #undef lgammal
95 #undef llrint
96 #undef llrintf
97 #undef llrintl
98 #undef llround
99 #undef llroundf
100 #undef llroundl
101 #undef log1p
102 #undef log1pf
103 #undef log1pl
104 #undef log2
105 #undef log2f
106 #undef log2l
107 #undef logb
108 #undef logbf
109 #undef logbl
110 #undef lrint
111 #undef lrintf
112 #undef lrintl
113 #undef lround
114 #undef lroundf
115 #undef lroundl
116 #undef nan
117 #undef nanf
118 #undef nanl
119 #undef nearbyint
120 #undef nearbyintf
121 #undef nearbyintl
122 #undef nextafter
123 #undef nextafterf
124 #undef nextafterl
125 #undef nexttoward
126 #undef nexttowardf
127 #undef nexttowardl
128 #undef remainder
129 #undef remainderf
130 #undef remainderl
131 #undef remquo
132 #undef remquof
133 #undef remquol
134 #undef rint
135 #undef rintf
136 #undef rintl
137 #undef round
138 #undef roundf
139 #undef roundl
140 #undef scalbln
141 #undef scalblnf
142 #undef scalblnl
143 #undef scalbn
144 #undef scalbnf
145 #undef scalbnl
146 #undef tgamma
147 #undef tgammaf
148 #undef tgammal
149 #undef trunc
150 #undef truncf
151 #undef truncl
152
153
154 #ifdef __BIONIC__
155 // XXX: Old versions of Bionic do not define %::float_t and %::double_t. These
156 // declarations should be compatible with new versions.
157 using float_t = float;
158 using double_t = double;
159 #else
160 using ::double_t;
161 using ::float_t;
162 #endif
163
164 // XXX: Detection of availability of 'long double' is not necessarily reliable.
165 // Be conservative.
166 # define YB_LibDefect_CMath_using_f(_fn) \
167 using ::_fn; \
168 using ::_fn##f;
169 # define YB_LibDefect_CMath_using_fl(_fn) \
170 YB_LibDefect_CMath_using_f(_fn) \
171 using ::_fn##l;
172
173 // NOTE: In Bionic some functions supporting 'long double' are introduced
174 // since API level 21. They are not respected here because most of them are
175 // renamed symbols (by assembly) which do not provide significant better
176 // choices in C++, and there may have architectural issues among different
177 // versions. Since %__BIONIC__ does not expose a reliable way to detect the
178 // version of libc, no further work is done here. Further, libstdc++ is already
179 // not supported for new versions of NDK, this header should normally not used
180 // for new NDK versions (e.g. by tested configurations of YSLib, since NDK
181 // r9c).
182 #ifndef __BIONIC__
183 # define YB_LibDefect_CMath_using(_fn) \
184 YB_LibDefect_CMath_using_fl(_fn)
185 #else
186 # define YB_LibDefect_CMath_using(_fn) \
187 YB_LibDefect_CMath_using_f(_fn)
188 #endif
189
190 YB_LibDefect_CMath_using(acos)
191 YB_LibDefect_CMath_using(asin)
192 YB_LibDefect_CMath_using(atan)
193 YB_LibDefect_CMath_using(cbrt)
194 YB_LibDefect_CMath_using(copysign)
195 YB_LibDefect_CMath_using(erf)
196 YB_LibDefect_CMath_using(erfc)
197 YB_LibDefect_CMath_using(exp2)
198 YB_LibDefect_CMath_using(expm1)
199 YB_LibDefect_CMath_using(fdim)
200 YB_LibDefect_CMath_using(fma)
201 YB_LibDefect_CMath_using(fmax)
202 YB_LibDefect_CMath_using(fmin)
203 YB_LibDefect_CMath_using(hypot)
204 YB_LibDefect_CMath_using(ilogb)
205 YB_LibDefect_CMath_using(lgamma)
206 YB_LibDefect_CMath_using(llrint)
207 YB_LibDefect_CMath_using(llround)
208 YB_LibDefect_CMath_using(log1p)
209 #ifndef __BIONIC__
210 # ifndef _NEWLIB_VERSION
211 YB_LibDefect_CMath_using(log2)
212 # else
213 YB_LibDefect_CMath_using_f(log2)
214 # endif
215 #endif
216 #ifndef _NEWLIB_VERSION
217 YB_LibDefect_CMath_using_f(logb)
218 #else
219 YB_LibDefect_CMath_using(lrint)
220 #endif
221 YB_LibDefect_CMath_using(lround)
222 #ifndef __BIONIC__
223 YB_LibDefect_CMath_using(nan)
224 #endif
225 YB_LibDefect_CMath_using(nearbyint)
226 YB_LibDefect_CMath_using(nextafter)
227 #ifndef _NEWLIB_VERSION
228 YB_LibDefect_CMath_using(nexttoward)
229 #endif
230 YB_LibDefect_CMath_using(remainder)
231 YB_LibDefect_CMath_using(remquo)
232 YB_LibDefect_CMath_using(rint)
233 YB_LibDefect_CMath_using(round)
234 YB_LibDefect_CMath_using(scalbln)
235 YB_LibDefect_CMath_using(scalbn)
236 #ifndef __BIONIC__
237 YB_LibDefect_CMath_using(tgamma)
238 #else
239 using ::tgamma;
240 #endif
241 YB_LibDefect_CMath_using(trunc)
242
243 #undef YB_LibDefect_CMath_using
244 #undef YB_LibDefect_CMath_using_fl
245 #undef YB_LibDefect_CMath_using_f
246
247 #if __clang__
248 // NOTE: See also https://llvm.org/bugs/show_bug.cgi?id=18327.
249 # define YB_LibDefect_CMath_constfn inline
250 #else
251 # define YB_LibDefect_CMath_constfn constexpr
252 #endif
253
254 #define YB_LibDefect_CMath_builtin(_n, ...) \
255 { \
256 return __builtin_##_n(__VA_ARGS__); \
257 }
258 #define YB_LibDefect_CMath_fn(_t, _fn, _n) \
259 YB_LibDefect_CMath_constfn _t \
260 _fn(_t __x) \
261 YB_LibDefect_CMath_builtin(_n, __x)
262 #define YB_LibDefect_CMath_fn2(_t, _fn, _n) \
263 YB_LibDefect_CMath_constfn _t \
264 _fn(_t __x, _t __y) \
265 YB_LibDefect_CMath_builtin(_n, __x, __y)
266 #define YB_LibDefect_CMath_fns(_fn) \
267 YB_LibDefect_CMath_fn(float, _fn, _fn##f) \
268 YB_LibDefect_CMath_fn(long double, _fn, _fn##l) \
269 template<typename _Tp> \
270 YB_LibDefect_CMath_constfn typename \
271 __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, double>::__type \
272 _fn(_Tp __x) \
273 YB_LibDefect_CMath_builtin(_fn, __x)
274 #define YB_LibDefect_CMath_fns2(_fn) \
275 YB_LibDefect_CMath_fn2(float, _fn, _fn##f) \
276 YB_LibDefect_CMath_fn2(long double, _fn, _fn##l) \
277 template<typename _Tp, typename _Up> \
278 YB_LibDefect_CMath_constfn \
279 typename __gnu_cxx::__promote_2<_Tp, _Up>::__type \
280 _fn(_Tp __x, _Up __y) \
281 { \
282 using __type = typename __gnu_cxx::__promote_2<_Tp, _Up>::__type; \
283 \
284 return _fn(__type(__x), __type(__y)); \
285 }
286
287 #define YB_LibDefect_CMath_trigo(_n) \
288 YB_LibDefect_CMath_fns(a##_n##h)
289
290 YB_LibDefect_CMath_trigo(cos)
291
292 YB_LibDefect_CMath_trigo(sin)
293
294 YB_LibDefect_CMath_trigo(tan)
295
296 #undef YB_LibDefect_CMath_trigo
297
298 YB_LibDefect_CMath_fns(cbrt)
299
300 YB_LibDefect_CMath_fns2(copysign)
301
302 YB_LibDefect_CMath_fns(erf)
303
304 YB_LibDefect_CMath_fns(erfc)
305
306 YB_LibDefect_CMath_fns(exp2)
307
308 YB_LibDefect_CMath_fns(expm1)
309
310 YB_LibDefect_CMath_fns2(fdim)
311
312 YB_LibDefect_CMath_constfn float
313 fma(float __x, float __y, float __z)
314 YB_LibDefect_CMath_builtin(fmaf, __x, __y, __z)
315 YB_LibDefect_CMath_constfn long double
316 fma(long double __x, long double __y, long double __z)
317 YB_LibDefect_CMath_builtin(fmal, __x, __y, __z)
318 template<typename _Tp, typename _Up, typename _Vp>
319 YB_LibDefect_CMath_constfn \
320 typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
321 fma(_Tp __x, _Up __y, _Vp __z)
322 {
323 using __type = typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type;
324
325 return fma(__type(__x), __type(__y), __type(__z));
326 }
327
328 YB_LibDefect_CMath_fns2(fmax)
329
330 YB_LibDefect_CMath_fns2(fmin)
331
332 YB_LibDefect_CMath_fns2(hypot)
333
334 YB_LibDefect_CMath_fns(ilogb)
335
336 YB_LibDefect_CMath_fns(lgamma)
337
338 YB_LibDefect_CMath_fns(llrint)
339
340 YB_LibDefect_CMath_fns(llround)
341
342 YB_LibDefect_CMath_fns(log1p)
343
344 // DR 568.
345 YB_LibDefect_CMath_fns(log2)
346
347 YB_LibDefect_CMath_fns(logb)
348
349 YB_LibDefect_CMath_fns(lrint)
350
351 YB_LibDefect_CMath_fns(lround)
352
353 YB_LibDefect_CMath_fns(nearbyint)
354
355 YB_LibDefect_CMath_fns2(nextafter)
356
357 YB_LibDefect_CMath_constfn float
358 nexttoward(float __x, long double __y)
359 YB_LibDefect_CMath_builtin(nexttowardf, __x, __y)
360 YB_LibDefect_CMath_constfn long double
361 nexttoward(long double __x, long double __y)
362 YB_LibDefect_CMath_builtin(nexttowardl, __x, __y)
363 template<typename _Tp>
364 YB_LibDefect_CMath_constfn
365 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, double>::__type
366 nexttoward(_Tp __x, long double __y)
367 YB_LibDefect_CMath_builtin(nexttoward, __x, __y)
368
369 YB_LibDefect_CMath_fns2(remainder)
370
371 inline float
372 remquo(float __x, float __y, int* __pquo)
373 YB_LibDefect_CMath_builtin(remquof, __x, __y, __pquo)
374 inline long double
375 remquo(long double __x, long double __y, int* __pquo)
376 YB_LibDefect_CMath_builtin(remquol, __x, __y, __pquo)
377 template<typename _Tp, typename _Up>
378 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
379 remquo(_Tp __x, _Up __y, int* __pquo)
380 {
381 using __type = typename __gnu_cxx::__promote_2<_Tp, _Up>::__type;
382
383 return remquo(__type(__x), __type(__y), __pquo);
384 }
385
386 YB_LibDefect_CMath_fns(rint)
387
388 YB_LibDefect_CMath_fns(round)
389
390 YB_LibDefect_CMath_constfn float
391 scalbln(float __x, long __ex)
392 YB_LibDefect_CMath_builtin(scalblnf, __x, __ex)
393 YB_LibDefect_CMath_constfn long double
394 scalbln(long double __x, long __ex)
395 YB_LibDefect_CMath_builtin(scalblnl, __x, __ex)
396 template<typename _Tp>
397 YB_LibDefect_CMath_constfn
398 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, double>::__type
399 scalbln(_Tp __x, long __ex)
400 YB_LibDefect_CMath_builtin(scalbln, __x, __ex)
401
402 YB_LibDefect_CMath_constfn float
403 scalbn(float __x, int __ex)
404 YB_LibDefect_CMath_builtin(scalbnf, __x, __ex)
405 YB_LibDefect_CMath_constfn long double
406 scalbn(long double __x, int __ex)
407 YB_LibDefect_CMath_builtin(scalbnl, __x, __ex)
408 template<typename _Tp>
409 YB_LibDefect_CMath_constfn
410 typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, double>::__type
411 scalbn(_Tp __x, int __ex)
412 YB_LibDefect_CMath_builtin(scalbn, __x, __ex)
413
414 YB_LibDefect_CMath_fns(tgamma)
415
416 YB_LibDefect_CMath_fns(trunc)
417
418 #undef YB_LibDefect_CMath_fns
419 #undef YB_LibDefect_CMath_fn2
420 #undef YB_LibDefect_CMath_fn
421 #undef YB_LibDefect_CMath_builtin
422 #undef YB_LibDefect_CMath_constfn
423
424 #ifdef _GLIBCXX_END_NAMESPACE_VERSION
425 _GLIBCXX_END_NAMESPACE_VERSION
426 #endif
427
428 } // namespace std;
429
430 } // extern "C++";
431
432 #endif
433
434 #endif
435
std
Definition: optional.h:982