[PATCH] libstdc++: add uniform on sphere distribution

Paolo Carlini paolo.carlini@oracle.com
Wed Aug 13 11:25:00 GMT 2014


... fixed with the below.

Thanks,
Paolo.

//////////////////////
-------------- next part --------------
2014-08-13  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/62118
	* include/ext/random.tcc (uniform_on_sphere_helper<2, _RealType>::
	operator()): Use std::hypot only when _GLIBCXX_USE_C99_MATH_TR1.
-------------- next part --------------
Index: include/ext/random.tcc
===================================================================
--- include/ext/random.tcc	(revision 213898)
+++ include/ext/random.tcc	(working copy)
@@ -1547,10 +1547,12 @@
     template<std::size_t _Dimen, typename _RealType>
       class uniform_on_sphere_helper
       {
-	typedef typename uniform_on_sphere_distribution<_Dimen, _RealType>::result_type result_type;
+	typedef typename uniform_on_sphere_distribution<_Dimen, _RealType>::
+	  result_type result_type;
 
       public:
-	template<typename _NormalDistribution, typename _UniformRandomNumberGenerator>
+	template<typename _NormalDistribution,
+		 typename _UniformRandomNumberGenerator>
 	result_type operator()(_NormalDistribution& __nd,
 			       _UniformRandomNumberGenerator& __urng)
         {
@@ -1604,9 +1606,13 @@
 	    }
 	  while (__sq == _RealType(0) || __sq > _RealType(1));
 
+#if _GLIBCXX_USE_C99_MATH_TR1
 	  // Yes, we do not just use sqrt(__sq) because hypot() is more
 	  // accurate.
 	  auto __norm = std::hypot(__ret[0], __ret[1]);
+#else
+	  auto __norm = std::sqrt(__ret[0] * __ret[0] + __ret[1] * __ret[1]);
+#endif
 	  __ret[0] /= __norm;
 	  __ret[1] /= __norm;
 


More information about the Libstdc++ mailing list