]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/ext/random.tcc
Add the rice distribution as an extension.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / random.tcc
index 988dc22282995202fd04d6734a8be540355e357e..6aa049a4f87c1961ae57d5806f12486ed432605b 100644 (file)
@@ -751,6 +751,78 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
 
+  template<typename _RealType>
+    template<typename _OutputIterator,
+            typename _UniformRandomNumberGenerator>
+      void
+      rice_distribution<_RealType>::
+      __generate_impl(_OutputIterator __f, _OutputIterator __t,
+                     _UniformRandomNumberGenerator& __urng,
+                     const param_type& __p)
+      {
+       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>)
+
+       std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+         __aurng(__urng);
+
+       while (__f != __t)
+         {
+           typename std::normal_distribution<result_type>::param_type
+             __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma());
+           result_type __x = this->_M_ndx(__px, __urng);
+           result_type __y = this->_M_ndy(__py, __urng);
+           *__f++ = std::hypot(__x, __y);
+         }
+      }
+
+  template<typename _RealType, typename _CharT, typename _Traits>
+    std::basic_ostream<_CharT, _Traits>&
+    operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+              const rice_distribution<_RealType>& __x)
+    {
+      typedef std::basic_ostream<_CharT, _Traits>  __ostream_type;
+      typedef typename __ostream_type::ios_base    __ios_base;
+
+      const typename __ios_base::fmtflags __flags = __os.flags();
+      const _CharT __fill = __os.fill();
+      const std::streamsize __precision = __os.precision();
+      const _CharT __space = __os.widen(' ');
+      __os.flags(__ios_base::scientific | __ios_base::left);
+      __os.fill(__space);
+      __os.precision(std::numeric_limits<_RealType>::max_digits10);
+
+      __os << __x.nu() << __space << __x.sigma();
+      __os << __space << __x._M_ndx;
+      __os << __space << __x._M_ndy;
+
+      __os.flags(__flags);
+      __os.fill(__fill);
+      __os.precision(__precision);
+      return __os;
+    }
+
+  template<typename _RealType, typename _CharT, typename _Traits>
+    std::basic_istream<_CharT, _Traits>&
+    operator>>(std::basic_istream<_CharT, _Traits>& __is,
+              rice_distribution<_RealType>& __x)
+    {
+      typedef std::basic_istream<_CharT, _Traits>  __istream_type;
+      typedef typename __istream_type::ios_base    __ios_base;
+
+      const typename __ios_base::fmtflags __flags = __is.flags();
+      __is.flags(__ios_base::dec | __ios_base::skipws);
+
+      _RealType __nu, __sigma;
+      __is >> __nu >> __sigma;
+      __is >> __x._M_ndx;
+      __is >> __x._M_ndy;
+      __x.param(typename rice_distribution<_RealType>::
+               param_type(__nu, __sigma));
+
+      __is.flags(__flags);
+      return __is;
+    }
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace