[libcxx-commits] [PATCH] D57778: std::abs should not return double (2735)
Zoe Carver via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 5 12:16:22 PST 2019
zoecarver created this revision.
zoecarver added reviewers: rsmith, mclow.lists.
Herald added subscribers: libcxx-commits, ldionne.
Implement 2735 <https://cplusplus.github.io/LWG/issue2735> by checking to make sure argument both `is_integral` and not `is_unsigned`.
**Question**
The issue describes `abs` returning an int always but for larger int types this would not work. I assume checking to make sure they are integral types is okay, but I am not sure.
Repository:
rCXX libc++
https://reviews.llvm.org/D57778
Files:
include/math.h
Index: include/math.h
===================================================================
--- include/math.h
+++ include/math.h
@@ -766,6 +766,14 @@
inline _LIBCPP_INLINE_VISIBILITY
long double
abs(long double __lcpp_x) _NOEXCEPT {return ::fabsl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<
+ std::is_integral<_A1>::value &&
+ !std::is_unsigned<_A1>::value, // allows for long long int, long int, int
+_A1>::type
+abs(_A1 __lcpp_x) _NOEXCEPT {return abs(__lcpp_x);}
#endif // !(defined(_AIX) || defined(__sun__))
// acos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57778.185370.patch
Type: text/x-patch
Size: 589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190205/b2406bce/attachment.bin>
More information about the libcxx-commits
mailing list