diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2016-05-17 14:52:19 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2016-05-17 14:52:19 +0000 |
commit | 4328c2bac88b6685e5f1e1fc8e14a58a9c0e7bd3 (patch) | |
tree | c6c06e71695d786f4c17274a5e0c83d1085cf98b | |
parent | bbd10b4579ef13707e97a06e7c7b981600f9d9e1 (diff) | |
download | bcm5719-llvm-4328c2bac88b6685e5f1e1fc8e14a58a9c0e7bd3.tar.gz bcm5719-llvm-4328c2bac88b6685e5f1e1fc8e14a58a9c0e7bd3.zip |
Implement P0030R1: Introduce a 3-Argument Overload to std::hypot
llvm-svn: 269772
-rw-r--r-- | libcxx/include/cmath | 28 | ||||
-rw-r--r-- | libcxx/test/std/numerics/c.math/cmath.pass.cpp | 23 | ||||
-rw-r--r-- | libcxx/www/cxx1z_status.html | 2 |
3 files changed, 52 insertions, 1 deletions
diff --git a/libcxx/include/cmath b/libcxx/include/cmath index ebbde18168f..b3e959405e9 100644 --- a/libcxx/include/cmath +++ b/libcxx/include/cmath @@ -209,6 +209,10 @@ floating_point hypot (arithmetic x, arithmetic y); float hypotf(float x, float y); long double hypotl(long double x, long double y); +double hypot(double x, double y, double z); // C++17 +float hypot(float x, float y, float z); // C++17 +long double hypot(long double x, long double y, long double z); // C++17 + int ilogb (arithmetic x); int ilogbf(float x); int ilogbl(long double x); @@ -548,6 +552,30 @@ using ::lgamma; using ::lgammaf; #endif // __sun__ +#if _LIBCPP_STD_VER > 14 +inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } +inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); } +inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); } + +template <class _A1, class _A2, class _A3> +inline _LIBCPP_INLINE_VISIBILITY +typename std::__lazy_enable_if +< + std::is_arithmetic<_A1>::value && + std::is_arithmetic<_A2>::value && + std::is_arithmetic<_A3>::value, + std::__promote<_A1, _A2, _A3> +>::type +hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT +{ + typedef typename std::__promote<_A1, _A2, _A3>::type __result_type; + static_assert((!(std::is_same<_A1, __result_type>::value && + std::is_same<_A2, __result_type>::value && + std::is_same<_A3, __result_type>::value)), ""); + return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); +} +#endif + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CMATH diff --git a/libcxx/test/std/numerics/c.math/cmath.pass.cpp b/libcxx/test/std/numerics/c.math/cmath.pass.cpp index 0b0d8628873..5b78925f0dc 100644 --- a/libcxx/test/std/numerics/c.math/cmath.pass.cpp +++ b/libcxx/test/std/numerics/c.math/cmath.pass.cpp @@ -79,6 +79,7 @@ Ambiguous fma(Ambiguous, Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous fmax(Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous fmin(Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous hypot(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous hypot(Ambiguous, Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous ilogb(Ambiguous){ return Ambiguous(); } Ambiguous lgamma(Ambiguous){ return Ambiguous(); } Ambiguous llrint(Ambiguous){ return Ambiguous(); } @@ -1010,6 +1011,28 @@ void test_hypot() static_assert((std::is_same<decltype(std::hypot((int)0, (int)0)), double>::value), ""); static_assert((std::is_same<decltype(hypot(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); assert(std::hypot(3,4) == 5); + +#if TEST_STD_VER > 14 + static_assert((std::is_same<decltype(std::hypot((float)0, (float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((int)0, (int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(hypot(Ambiguous(), Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + + assert(std::hypot(2,3,6) == 7); + assert(std::hypot(1,4,8) == 9); +#endif } void test_ilogb() diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index 23824e4bfa0..3725c5c6373 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -89,7 +89,7 @@ <tr><td><a href="http://wg21.link/P0253R1">P0253R1</a></td><td>LWG</td><td>Fixing a design mistake in the searchers interface</td><td>Jacksonville</td><td>Complete</td><td>3.9</td></tr> <tr><td><a href="http://wg21.link/P0025R0">P0025R0</a></td><td>LWG</td><td>An algorithm to "clamp" a value between a pair of boundary values</td><td>Jacksonville</td><td>Complete</td><td>3.9</td></tr> <tr><td><a href="http://wg21.link/P0154R1">P0154R1</a></td><td>LWG</td><td>constexpr std::hardware_{constructive,destructive}_interference_size</td><td>Jacksonville</td><td></td><td></td></tr> - <tr><td><a href="http://wg21.link/P0030R1">P0030R1</a></td><td>LWG</td><td>Proposal to Introduce a 3-Argument Overload to std::hypot</td><td>Jacksonville</td><td></td><td></td></tr> + <tr><td><a href="http://wg21.link/P0030R1">P0030R1</a></td><td>LWG</td><td>Proposal to Introduce a 3-Argument Overload to std::hypot</td><td>Jacksonville</td><td>Complete</td><td>3.9</td></tr> <tr><td><a href="http://wg21.link/P0031R0">P0031R0</a></td><td>LWG</td><td>A Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range Access</td><td>Jacksonville</td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/P0272R1">P0272R1</a></td><td>LWG</td><td>Give <tt>std::string</tt> a non-const <tt>.data()</tt> member function</td><td>Jacksonville</td><td>Complete</td><td>3.9</td></tr> <tr><td><a href="http://wg21.link/P0077R2">P0077R2</a></td><td>LWG</td><td><tt>is_callable</tt>, the missing INVOKE related trait</td><td>Jacksonville</td><td>Complete</td><td>3.9</td></tr> |