inverse_trigonometric_functions.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_INVERSE_TRIGONOMETRIC_FUNCTIONS_H
  9. #define _LIBCPP___MATH_INVERSE_TRIGONOMETRIC_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. // acos
  22. inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT { return __builtin_acosf(__x); }
  23. template <class = int>
  24. _LIBCPP_HIDE_FROM_ABI double acos(double __x) _NOEXCEPT {
  25. return __builtin_acos(__x);
  26. }
  27. inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT { return __builtin_acosl(__x); }
  28. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  29. inline _LIBCPP_HIDE_FROM_ABI double acos(_A1 __x) _NOEXCEPT {
  30. return __builtin_acos((double)__x);
  31. }
  32. // asin
  33. inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT { return __builtin_asinf(__x); }
  34. template <class = int>
  35. _LIBCPP_HIDE_FROM_ABI double asin(double __x) _NOEXCEPT {
  36. return __builtin_asin(__x);
  37. }
  38. inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT { return __builtin_asinl(__x); }
  39. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  40. inline _LIBCPP_HIDE_FROM_ABI double asin(_A1 __x) _NOEXCEPT {
  41. return __builtin_asin((double)__x);
  42. }
  43. // atan
  44. inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT { return __builtin_atanf(__x); }
  45. template <class = int>
  46. _LIBCPP_HIDE_FROM_ABI double atan(double __x) _NOEXCEPT {
  47. return __builtin_atan(__x);
  48. }
  49. inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT { return __builtin_atanl(__x); }
  50. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  51. inline _LIBCPP_HIDE_FROM_ABI double atan(_A1 __x) _NOEXCEPT {
  52. return __builtin_atan((double)__x);
  53. }
  54. // atan2
  55. inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT { return __builtin_atan2f(__y, __x); }
  56. template <class = int>
  57. _LIBCPP_HIDE_FROM_ABI double atan2(double __x, double __y) _NOEXCEPT {
  58. return __builtin_atan2(__x, __y);
  59. }
  60. inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x) _NOEXCEPT {
  61. return __builtin_atan2l(__y, __x);
  62. }
  63. template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
  64. inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type atan2(_A1 __y, _A2 __x) _NOEXCEPT {
  65. using __result_type = typename __promote<_A1, _A2>::type;
  66. static_assert((!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value)), "");
  67. return __math::atan2((__result_type)__y, (__result_type)__x);
  68. }
  69. } // namespace __math
  70. _LIBCPP_END_NAMESPACE_STD
  71. #endif // _LIBCPP___MATH_INVERSE_TRIGONOMETRIC_FUNCTIONS_H