| 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___CXX03___MATH_LOGARITHMS_H |
| 10 |
#define _LIBCPP___CXX03___MATH_LOGARITHMS_H |
| 11 |
|
| 12 |
#include <__cxx03/__config> |
| 13 |
#include <__cxx03/__type_traits/enable_if.h> |
| 14 |
#include <__cxx03/__type_traits/is_integral.h> |
| 15 |
|
| 16 |
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 17 |
# pragma GCC system_header |
| 18 |
#endif |
| 19 |
|
| 20 |
_LIBCPP_BEGIN_NAMESPACE_STD |
| 21 |
|
| 22 |
namespace __math { |
| 23 |
|
| 24 |
// log |
| 25 |
|
| 26 |
inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT { return __builtin_logf(__x); } |
| 27 |
|
| 28 |
template <class = int> |
| 29 |
_LIBCPP_HIDE_FROM_ABI double log(double __x) _NOEXCEPT { |
| 30 |
return __builtin_log(__x); |
| 31 |
} |
| 32 |
|
| 33 |
inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT { return __builtin_logl(__x); } |
| 34 |
|
| 35 |
template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0> |
| 36 |
inline _LIBCPP_HIDE_FROM_ABI double log(_A1 __x) _NOEXCEPT { |
| 37 |
return __builtin_log((double)__x); |
| 38 |
} |
| 39 |
|
| 40 |
// log10 |
| 41 |
|
| 42 |
inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT { return __builtin_log10f(__x); } |
| 43 |
|
| 44 |
template <class = int> |
| 45 |
_LIBCPP_HIDE_FROM_ABI double log10(double __x) _NOEXCEPT { |
| 46 |
return __builtin_log10(__x); |
| 47 |
} |
| 48 |
|
| 49 |
inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT { return __builtin_log10l(__x); } |
| 50 |
|
| 51 |
template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0> |
| 52 |
inline _LIBCPP_HIDE_FROM_ABI double log10(_A1 __x) _NOEXCEPT { |
| 53 |
return __builtin_log10((double)__x); |
| 54 |
} |
| 55 |
|
| 56 |
// ilogb |
| 57 |
|
| 58 |
inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT { return __builtin_ilogbf(__x); } |
| 59 |
|
| 60 |
template <class = int> |
| 61 |
_LIBCPP_HIDE_FROM_ABI int ilogb(double __x) _NOEXCEPT { |
| 62 |
return __builtin_ilogb(__x); |
| 63 |
} |
| 64 |
|
| 65 |
inline _LIBCPP_HIDE_FROM_ABI int ilogb(long double __x) _NOEXCEPT { return __builtin_ilogbl(__x); } |
| 66 |
|
| 67 |
template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0> |
| 68 |
inline _LIBCPP_HIDE_FROM_ABI int ilogb(_A1 __x) _NOEXCEPT { |
| 69 |
return __builtin_ilogb((double)__x); |
| 70 |
} |
| 71 |
|
| 72 |
// log1p |
| 73 |
|
| 74 |
inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT { return __builtin_log1pf(__x); } |
| 75 |
|
| 76 |
template <class = int> |
| 77 |
_LIBCPP_HIDE_FROM_ABI double log1p(double __x) _NOEXCEPT { |
| 78 |
return __builtin_log1p(__x); |
| 79 |
} |
| 80 |
|
| 81 |
inline _LIBCPP_HIDE_FROM_ABI long double log1p(long double __x) _NOEXCEPT { return __builtin_log1pl(__x); } |
| 82 |
|
| 83 |
template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0> |
| 84 |
inline _LIBCPP_HIDE_FROM_ABI double log1p(_A1 __x) _NOEXCEPT { |
| 85 |
return __builtin_log1p((double)__x); |
| 86 |
} |
| 87 |
|
| 88 |
// log2 |
| 89 |
|
| 90 |
inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT { return __builtin_log2f(__x); } |
| 91 |
|
| 92 |
template <class = int> |
| 93 |
_LIBCPP_HIDE_FROM_ABI double log2(double __x) _NOEXCEPT { |
| 94 |
return __builtin_log2(__x); |
| 95 |
} |
| 96 |
|
| 97 |
inline _LIBCPP_HIDE_FROM_ABI long double log2(long double __x) _NOEXCEPT { return __builtin_log2l(__x); } |
| 98 |
|
| 99 |
template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0> |
| 100 |
inline _LIBCPP_HIDE_FROM_ABI double log2(_A1 __x) _NOEXCEPT { |
| 101 |
return __builtin_log2((double)__x); |
| 102 |
} |
| 103 |
|
| 104 |
// logb |
| 105 |
|
| 106 |
inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT { return __builtin_logbf(__x); } |
| 107 |
|
| 108 |
template <class = int> |
| 109 |
_LIBCPP_HIDE_FROM_ABI double logb(double __x) _NOEXCEPT { |
| 110 |
return __builtin_logb(__x); |
| 111 |
} |
| 112 |
|
| 113 |
inline _LIBCPP_HIDE_FROM_ABI long double logb(long double __x) _NOEXCEPT { return __builtin_logbl(__x); } |
| 114 |
|
| 115 |
template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0> |
| 116 |
inline _LIBCPP_HIDE_FROM_ABI double logb(_A1 __x) _NOEXCEPT { |
| 117 |
return __builtin_logb((double)__x); |
| 118 |
} |
| 119 |
|
| 120 |
} // namespace __math |
| 121 |
|
| 122 |
_LIBCPP_END_NAMESPACE_STD |
| 123 |
|
| 124 |
#endif // _LIBCPP___CXX03___MATH_LOGARITHMS_H |