1// -*- C++ -*- C forwarding header. 2 3// Copyright (C) 1997-2015 Free Software Foundation, Inc. 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 3, or (at your option) 9// any later version. 10 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16// Under Section 7 of GPL version 3, you are granted additional 17// permissions described in the GCC Runtime Library Exception, version 18// 3.1, as published by the Free Software Foundation. 19 20// You should have received a copy of the GNU General Public License and 21// a copy of the GCC Runtime Library Exception along with this program; 22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23// <http://www.gnu.org/licenses/>. 24 25/** @file include/cmath 26 * This is a Standard C++ Library file. You should @c #include this file 27 * in your programs, rather than any of the @a *.h implementation files. 28 * 29 * This is the C++ version of the Standard C Library header @c math.h, 30 * and its contents are (mostly) the same as that header, but are all 31 * contained in the namespace @c std (except for names which are defined 32 * as macros in C). 33 */ 34 35// 36// ISO C++ 14882: 26.5 C library 37// 38 39#ifndef _GLIBCXX_CMATH 40#define _GLIBCXX_CMATH 1 41 42#pragma GCC system_header 43 44#include <bits/c++config.h> 45#include <bits/cpp_type_traits.h> 46#include <ext/type_traits.h> 47 48#include <math.h> 49 50// Get rid of those macros defined in <math.h> in lieu of real functions. 51#undef abs 52#undef div 53#undef acos 54#undef asin 55#undef atan 56#undef atan2 57#undef ceil 58#undef cos 59#undef cosh 60#undef exp 61#undef fabs 62#undef floor 63#undef fmod 64#undef frexp 65#undef ldexp 66#undef log 67#undef log10 68#undef modf 69#undef pow 70#undef sin 71#undef sinh 72#undef sqrt 73#undef tan 74#undef tanh 75 76namespace std _GLIBCXX_VISIBILITY(default) 77{ 78_GLIBCXX_BEGIN_NAMESPACE_VERSION 79 80 inline double 81 abs(double __x) 82 { return __builtin_fabs(__x); } 83 84 inline float 85 abs(float __x) 86 { return __builtin_fabsf(__x); } 87 88 inline long double 89 abs(long double __x) 90 { return __builtin_fabsl(__x); } 91 92 template<typename _Tp> 93 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 94 double>::__type 95 abs(_Tp __x) 96 { return __builtin_fabs(__x); } 97 98 using ::acos; 99 100 inline float 101 acos(float __x) 102 { return __builtin_acosf(__x); } 103 104 inline long double 105 acos(long double __x) 106 { return __builtin_acosl(__x); } 107 108 template<typename _Tp> 109 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 110 double>::__type 111 acos(_Tp __x) 112 { return __builtin_acos(__x); } 113 114 using ::asin; 115 116 inline float 117 asin(float __x) 118 { return __builtin_asinf(__x); } 119 120 inline long double 121 asin(long double __x) 122 { return __builtin_asinl(__x); } 123 124 template<typename _Tp> 125 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 126 double>::__type 127 asin(_Tp __x) 128 { return __builtin_asin(__x); } 129 130 using ::atan; 131 132 inline float 133 atan(float __x) 134 { return __builtin_atanf(__x); } 135 136 inline long double 137 atan(long double __x) 138 { return __builtin_atanl(__x); } 139 140 template<typename _Tp> 141 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 142 double>::__type 143 atan(_Tp __x) 144 { return __builtin_atan(__x); } 145 146 using ::atan2; 147 148 inline float 149 atan2(float __y, float __x) 150 { return __builtin_atan2f(__y, __x); } 151 152 inline long double 153 atan2(long double __y, long double __x) 154 { return __builtin_atan2l(__y, __x); } 155 156 template<typename _Tp, typename _Up> 157 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value 158 && __is_integer<_Up>::__value, 159 double>::__type 160 atan2(_Tp __y, _Up __x) 161 { return __builtin_atan2(__y, __x); } 162 163 using ::ceil; 164 165 inline float 166 ceil(float __x) 167 { return __builtin_ceilf(__x); } 168 169 inline long double 170 ceil(long double __x) 171 { return __builtin_ceill(__x); } 172 173 template<typename _Tp> 174 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 175 double>::__type 176 ceil(_Tp __x) 177 { return __builtin_ceil(__x); } 178 179 using ::cos; 180 181 inline float 182 cos(float __x) 183 { return __builtin_cosf(__x); } 184 185 inline long double 186 cos(long double __x) 187 { return __builtin_cosl(__x); } 188 189 template<typename _Tp> 190 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 191 double>::__type 192 cos(_Tp __x) 193 { return __builtin_cos(__x); } 194 195 using ::cosh; 196 197 inline float 198 cosh(float __x) 199 { return __builtin_coshf(__x); } 200 201 inline long double 202 cosh(long double __x) 203 { return __builtin_coshl(__x); } 204 205 template<typename _Tp> 206 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 207 double>::__type 208 cosh(_Tp __x) 209 { return __builtin_cosh(__x); } 210 211 using ::exp; 212 213 inline float 214 exp(float __x) 215 { return __builtin_expf(__x); } 216 217 inline long double 218 exp(long double __x) 219 { return __builtin_expl(__x); } 220 221 template<typename _Tp> 222 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 223 double>::__type 224 exp(_Tp __x) 225 { return __builtin_exp(__x); } 226 227 using ::fabs; 228 229 inline float 230 fabs(float __x) 231 { return __builtin_fabsf(__x); } 232 233 inline long double 234 fabs(long double __x) 235 { return __builtin_fabsl(__x); } 236 237 template<typename _Tp> 238 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 239 double>::__type 240 fabs(_Tp __x) 241 { return __builtin_fabs(__x); } 242 243 using ::floor; 244 245 inline float 246 floor(float __x) 247 { return __builtin_floorf(__x); } 248 249 inline long double 250 floor(long double __x) 251 { return __builtin_floorl(__x); } 252 253 template<typename _Tp> 254 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 255 double>::__type 256 floor(_Tp __x) 257 { return __builtin_floor(__x); } 258 259 using ::fmod; 260 261 inline float 262 fmod(float __x, float __y) 263 { return __builtin_fmodf(__x, __y); } 264 265 inline long double 266 fmod(long double __x, long double __y) 267 { return __builtin_fmodl(__x, __y); } 268 269 template<typename _Tp, typename _Up> 270 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value 271 && __is_integer<_Up>::__value, 272 double>::__type 273 fmod(_Tp __x, _Up __y) 274 { return __builtin_fmod(__x, __y); } 275 276 using ::frexp; 277 278 inline float 279 frexp(float __x, int* __exp) 280 { return __builtin_frexpf(__x, __exp); } 281 282 inline long double 283 frexp(long double __x, int* __exp) 284 { return __builtin_frexpl(__x, __exp); } 285 286 template<typename _Tp> 287 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 288 double>::__type 289 frexp(_Tp __x, int* __exp) 290 { return __builtin_frexp(__x, __exp); } 291 292 using ::ldexp; 293 294 inline float 295 ldexp(float __x, int __exp) 296 { return __builtin_ldexpf(__x, __exp); } 297 298 inline long double 299 ldexp(long double __x, int __exp) 300 { return __builtin_ldexpl(__x, __exp); } 301 302 template<typename _Tp> 303 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 304 double>::__type 305 ldexp(_Tp __x, int __exp) 306 { return __builtin_ldexp(__x, __exp); } 307 308 using ::log; 309 310 inline float 311 log(float __x) 312 { return __builtin_logf(__x); } 313 314 inline long double 315 log(long double __x) 316 { return __builtin_logl(__x); } 317 318 template<typename _Tp> 319 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 320 double>::__type 321 log(_Tp __x) 322 { return __builtin_log(__x); } 323 324 using ::log10; 325 326 inline float 327 log10(float __x) 328 { return __builtin_log10f(__x); } 329 330 inline long double 331 log10(long double __x) 332 { return __builtin_log10l(__x); } 333 334 template<typename _Tp> 335 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 336 double>::__type 337 log10(_Tp __x) 338 { return __builtin_log10(__x); } 339 340 using ::modf; 341 342 inline float 343 modf(float __x, float* __iptr) 344 { return __builtin_modff(__x, __iptr); } 345 346 inline long double 347 modf(long double __x, long double* __iptr) 348 { return __builtin_modfl(__x, __iptr); } 349 350 using ::pow; 351 352 inline float 353 pow(float __x, float __y) 354 { return __builtin_powf(__x, __y); } 355 356 inline long double 357 pow(long double __x, long double __y) 358 { return __builtin_powl(__x, __y); } 359 360 inline double 361 pow(double __x, int __i) 362 { return __builtin_powi(__x, __i); } 363 364 inline float 365 pow(float __x, int __n) 366 { return __builtin_powif(__x, __n); } 367 368 inline long double 369 pow(long double __x, int __n) 370 { return __builtin_powil(__x, __n); } 371 372 using ::sin; 373 374 inline float 375 sin(float __x) 376 { return __builtin_sinf(__x); } 377 378 inline long double 379 sin(long double __x) 380 { return __builtin_sinl(__x); } 381 382 template<typename _Tp> 383 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 384 double>::__type 385 sin(_Tp __x) 386 { return __builtin_sin(__x); } 387 388 using ::sinh; 389 390 inline float 391 sinh(float __x) 392 { return __builtin_sinhf(__x); } 393 394 inline long double 395 sinh(long double __x) 396 { return __builtin_sinhl(__x); } 397 398 template<typename _Tp> 399 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 400 double>::__type 401 sinh(_Tp __x) 402 { return __builtin_sinh(__x); } 403 404 using ::sqrt; 405 406 inline float 407 sqrt(float __x) 408 { return __builtin_sqrtf(__x); } 409 410 inline long double 411 sqrt(long double __x) 412 { return __builtin_sqrtl(__x); } 413 414 template<typename _Tp> 415 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 416 double>::__type 417 sqrt(_Tp __x) 418 { return __builtin_sqrt(__x); } 419 420 using ::tan; 421 422 inline float 423 tan(float __x) 424 { return __builtin_tanf(__x); } 425 426 inline long double 427 tan(long double __x) 428 { return __builtin_tanl(__x); } 429 430 template<typename _Tp> 431 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 432 double>::__type 433 tan(_Tp __x) 434 { return __builtin_tan(__x); } 435 436 using ::tanh; 437 438 inline float 439 tanh(float __x) 440 { return __builtin_tanhf(__x); } 441 442 inline long double 443 tanh(long double __x) 444 { return __builtin_tanhl(__x); } 445 446 template<typename _Tp> 447 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 448 double>::__type 449 tanh(_Tp __x) 450 { return __builtin_tanh(__x); } 451 452_GLIBCXX_END_NAMESPACE_VERSION 453} // namespace 454 455#if _GLIBCXX_USE_C99_MATH 456#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC 457 458// These are possible macros imported from C99-land. 459#undef fpclassify 460#undef isfinite 461#undef isinf 462#undef isnan 463#undef isnormal 464#undef signbit 465#undef isgreater 466#undef isgreaterequal 467#undef isless 468#undef islessequal 469#undef islessgreater 470#undef isunordered 471 472namespace std _GLIBCXX_VISIBILITY(default) 473{ 474_GLIBCXX_BEGIN_NAMESPACE_VERSION 475 476 template<typename _Tp> 477 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 478 int>::__type 479 fpclassify(_Tp __f) 480 { 481 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 482 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, 483 FP_SUBNORMAL, FP_ZERO, __type(__f)); 484 } 485 486 template<typename _Tp> 487 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 488 int>::__type 489 isfinite(_Tp __f) 490 { 491 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 492 return __builtin_isfinite(__type(__f)); 493 } 494 495 template<typename _Tp> 496 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 497 int>::__type 498 isinf(_Tp __f) 499 { 500 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 501 return __builtin_isinf(__type(__f)); 502 } 503 504 template<typename _Tp> 505 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 506 int>::__type 507 isnan(_Tp __f) 508 { 509 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 510 return __builtin_isnan(__type(__f)); 511 } 512 513 template<typename _Tp> 514 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 515 int>::__type 516 isnormal(_Tp __f) 517 { 518 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 519 return __builtin_isnormal(__type(__f)); 520 } 521 522 template<typename _Tp> 523 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 524 int>::__type 525 signbit(_Tp __f) 526 { 527 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 528 return __builtin_signbit(__type(__f)); 529 } 530 531 template<typename _Tp> 532 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 533 int>::__type 534 isgreater(_Tp __f1, _Tp __f2) 535 { 536 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 537 return __builtin_isgreater(__type(__f1), __type(__f2)); 538 } 539 540 template<typename _Tp> 541 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 542 int>::__type 543 isgreaterequal(_Tp __f1, _Tp __f2) 544 { 545 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 546 return __builtin_isgreaterequal(__type(__f1), __type(__f2)); 547 } 548 549 template<typename _Tp> 550 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 551 int>::__type 552 isless(_Tp __f1, _Tp __f2) 553 { 554 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 555 return __builtin_isless(__type(__f1), __type(__f2)); 556 } 557 558 template<typename _Tp> 559 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 560 int>::__type 561 islessequal(_Tp __f1, _Tp __f2) 562 { 563 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 564 return __builtin_islessequal(__type(__f1), __type(__f2)); 565 } 566 567 template<typename _Tp> 568 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 569 int>::__type 570 islessgreater(_Tp __f1, _Tp __f2) 571 { 572 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 573 return __builtin_islessgreater(__type(__f1), __type(__f2)); 574 } 575 576 template<typename _Tp> 577 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, 578 int>::__type 579 isunordered(_Tp __f1, _Tp __f2) 580 { 581 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 582 return __builtin_isunordered(__type(__f1), __type(__f2)); 583 } 584 585_GLIBCXX_END_NAMESPACE_VERSION 586} // namespace std 587 588#endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */ 589#endif 590 591#endif 592