logarithms.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_LOGARITHMS_H
  9. #define _LIBCPP___MATH_LOGARITHMS_H
  10. #include <__config>
  11. #include <__type_traits/enable_if.h>
  12. #include <__type_traits/is_integral.h>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. namespace __math {
  18. // log
  19. inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT { return __builtin_logf(__x); }
  20. template <class = int>
  21. _LIBCPP_HIDE_FROM_ABI double log(double __x) _NOEXCEPT {
  22. return __builtin_log(__x);
  23. }
  24. inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT { return __builtin_logl(__x); }
  25. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  26. inline _LIBCPP_HIDE_FROM_ABI double log(_A1 __x) _NOEXCEPT {
  27. return __builtin_log((double)__x);
  28. }
  29. // log10
  30. inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT { return __builtin_log10f(__x); }
  31. template <class = int>
  32. _LIBCPP_HIDE_FROM_ABI double log10(double __x) _NOEXCEPT {
  33. return __builtin_log10(__x);
  34. }
  35. inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT { return __builtin_log10l(__x); }
  36. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  37. inline _LIBCPP_HIDE_FROM_ABI double log10(_A1 __x) _NOEXCEPT {
  38. return __builtin_log10((double)__x);
  39. }
  40. // ilogb
  41. inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT { return __builtin_ilogbf(__x); }
  42. template <class = int>
  43. _LIBCPP_HIDE_FROM_ABI double ilogb(double __x) _NOEXCEPT {
  44. return __builtin_ilogb(__x);
  45. }
  46. inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT { return __builtin_ilogbl(__x); }
  47. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  48. inline _LIBCPP_HIDE_FROM_ABI int ilogb(_A1 __x) _NOEXCEPT {
  49. return __builtin_ilogb((double)__x);
  50. }
  51. // log1p
  52. inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT { return __builtin_log1pf(__x); }
  53. template <class = int>
  54. _LIBCPP_HIDE_FROM_ABI double log1p(double __x) _NOEXCEPT {
  55. return __builtin_log1p(__x);
  56. }
  57. inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT { return __builtin_log1pl(__x); }
  58. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  59. inline _LIBCPP_HIDE_FROM_ABI double log1p(_A1 __x) _NOEXCEPT {
  60. return __builtin_log1p((double)__x);
  61. }
  62. // log2
  63. inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT { return __builtin_log2f(__x); }
  64. template <class = int>
  65. _LIBCPP_HIDE_FROM_ABI double log2(double __x) _NOEXCEPT {
  66. return __builtin_log2(__x);
  67. }
  68. inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT { return __builtin_log2l(__x); }
  69. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  70. inline _LIBCPP_HIDE_FROM_ABI double log2(_A1 __x) _NOEXCEPT {
  71. return __builtin_log2((double)__x);
  72. }
  73. // logb
  74. inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT { return __builtin_logbf(__x); }
  75. template <class = int>
  76. _LIBCPP_HIDE_FROM_ABI double logb(double __x) _NOEXCEPT {
  77. return __builtin_logb(__x);
  78. }
  79. inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT { return __builtin_logbl(__x); }
  80. template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
  81. inline _LIBCPP_HIDE_FROM_ABI double logb(_A1 __x) _NOEXCEPT {
  82. return __builtin_logb((double)__x);
  83. }
  84. } // namespace __math
  85. _LIBCPP_END_NAMESPACE_STD
  86. #endif // _LIBCPP___MATH_LOGARITHMS_H