Patchwork [v3] Add missing std::fmod overload

login
register
mail settings
Submitter Paolo Carlini
Date Aug. 12, 2011, 3:41 p.m.
Message ID <4E4549AF.6000704@oracle.com>
Download mbox | patch
Permalink /patch/109862/
State New
Headers show

Comments

Paolo Carlini - Aug. 12, 2011, 3:41 p.m.
Hi,

tested x86_64-linux, committed to mainline.

Paolo.

PS: will add separately tests for the C++11 <cmath> facilities.

//////////////
2011-08-12  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/c_global/cmath (fmod(_Tp, _Up)): Add.
	* include/c_std/cmath: Likewise.

Patch

Index: include/c_std/cmath
===================================================================
--- include/c_std/cmath	(revision 177696)
+++ include/c_std/cmath	(working copy)
@@ -268,6 +268,13 @@ 
   fmod(long double __x, long double __y)
   { return __builtin_fmodl(__x, __y); }
 
+  template<typename _Tp, typename _Up>
+    inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
+    					   && __is_integer<_Up>::__value, 
+					   double>::__type
+    fmod(_Tp __x, _Up __y)
+    { return __builtin_fmod(__x, __y); }
+
   using ::frexp;
 
   inline float
Index: include/c_global/cmath
===================================================================
--- include/c_global/cmath	(revision 177696)
+++ include/c_global/cmath	(working copy)
@@ -282,6 +282,18 @@ 
   fmod(long double __x, long double __y)
   { return __builtin_fmodl(__x, __y); }
 
+  template<typename _Tp, typename _Up>
+    inline _GLIBCXX_CONSTEXPR
+    typename __gnu_cxx::__promote_2<
+    typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value
+				    && __is_arithmetic<_Up>::__value,
+				    _Tp>::__type, _Up>::__type
+    fmod(_Tp __x, _Up __y)
+    {
+      typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
+      return fmod(__type(__x), __type(__y));
+    }
+
   using ::frexp;
 
   inline _GLIBCXX_CONSTEXPR float
@@ -313,8 +325,8 @@ 
     inline _GLIBCXX_CONSTEXPR
     typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
                                     double>::__type
-  ldexp(_Tp __x, int __exp)
-  { return __builtin_ldexp(__x, __exp); }
+    ldexp(_Tp __x, int __exp)
+    { return __builtin_ldexp(__x, __exp); }
 
   using ::log;