[cfe-commits] [libcxx] r103621 - in /libcxx/trunk: include/ test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/ test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/

Howard Hinnant hhinnant at apple.com
Wed May 12 10:08:57 PDT 2010


Author: hhinnant
Date: Wed May 12 12:08:57 2010
New Revision: 103621

URL: http://llvm.org/viewvc/llvm-project?rev=103621&view=rev
Log:
[rand.dist.pois.exp]

Added:
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_param.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp
Modified:
    libcxx/trunk/include/random
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp

Modified: libcxx/trunk/include/random
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/random?rev=103621&r1=103620&r2=103621&view=diff
==============================================================================
--- libcxx/trunk/include/random (original)
+++ libcxx/trunk/include/random Wed May 12 12:08:57 2010
@@ -675,7 +675,60 @@
     class poisson_distribution;
 
 template<class RealType = double>
-    class exponential_distribution;
+class exponential_distribution
+{
+public:
+    // types
+    typedef RealType result_type;
+
+    class param_type
+    {
+    public:
+        typedef exponential_distribution distribution_type;
+
+        explicit param_type(RealType lambda = 1.0);
+
+        RealType lambda() const;
+
+        friend bool operator==(const param_type& x, const param_type& y);
+        friend bool operator!=(const param_type& x, const param_type& y);
+    };
+
+    // constructors and reset functions
+    explicit exponential_distribution(RealType lambda = 1.0);
+    explicit exponential_distribution(const param_type& parm);
+    void reset();
+
+    // generating functions
+    template<class URNG> result_type operator()(URNG& g);
+    template<class URNG> result_type operator()(URNG& g, const param_type& parm);
+
+    // property functions
+    RealType lambda() const;
+
+    param_type param() const;
+    void param(const param_type& parm);
+
+    result_type min() const;
+    result_type max() const;
+
+    friend bool operator==(const exponential_distribution& x,
+                           const exponential_distribution& y);
+    friend bool operator!=(const exponential_distribution& x,
+                           const exponential_distribution& y);
+
+    template <class charT, class traits>
+    friend
+    basic_ostream<charT, traits>&
+    operator<<(basic_ostream<charT, traits>& os,
+               const exponential_distribution& x);
+    
+    template <class charT, class traits>
+    friend
+    basic_istream<charT, traits>&
+    operator>>(basic_istream<charT, traits>& is,
+               exponential_distribution& x);
+};
 
 template<class RealType = double>
     class gamma_distribution;
@@ -727,6 +780,7 @@
 #include <string>
 #include <istream>
 #include <ostream>
+#include <cmath>
 
 #pragma GCC system_header
 
@@ -2460,6 +2514,8 @@
     }
 }
 
+// generate_canonical
+
 template<class _RealType, size_t __bits, class _URNG>
 _RealType
 generate_canonical(_URNG& __g)
@@ -2599,6 +2655,8 @@
     return _S;
 }
 
+// uniform_int_distribution
+
 template<class _IntType = int>
 class uniform_int_distribution
 {
@@ -2716,6 +2774,8 @@
     return __is;
 }
 
+// uniform_real_distribution
+
 template<class _RealType = double>
 class uniform_real_distribution
 {
@@ -2817,6 +2877,8 @@
     return __is;
 }
 
+// bernoulli_distribution
+
 class bernoulli_distribution
 {
 public:
@@ -2905,6 +2967,8 @@
     return __is;
 }
 
+// binomial_distribution
+
 template<class _IntType = int>
 class binomial_distribution
 {
@@ -3007,6 +3071,106 @@
     return __is;
 }
 
+// exponential_distribution
+
+template<class _RealType = double>
+class exponential_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class param_type
+    {
+        result_type __lambda_;
+    public:
+        typedef exponential_distribution distribution_type;
+
+        explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {}
+
+        result_type lambda() const {return __lambda_;}
+
+        friend bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__lambda_ == __y.__lambda_;}
+        friend bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+    explicit exponential_distribution(result_type __lambda = 1)
+        : __p_(param_type(__lambda)) {}
+    explicit exponential_distribution(const param_type& __p) : __p_(__p) {}
+    void reset() {}
+
+    // generating functions
+    template<class _URNG> result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    result_type lambda() const {return __p_.lambda();}
+
+    param_type param() const {return __p_;}
+    void param(const param_type& __p) {__p_ = __p;}
+
+    result_type min() const {return 0;}
+    result_type max() const
+        {return -std::log(1-std::nextafter(result_type(1), result_type(-1))) /
+                 __p_.lambda();}
+
+    friend bool operator==(const exponential_distribution& __x,
+                           const exponential_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend bool operator!=(const exponential_distribution& __x,
+                           const exponential_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _RealType>
+template<class _URNG>
+_RealType
+exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    return -_STD::log
+                  (
+                      result_type(1) -
+                      _STD::generate_canonical<result_type,
+                                       numeric_limits<result_type>::digits>(__g)
+                  )
+                  / __p.lambda();
+}
+
+template <class _CharT, class _Traits, class _RealType>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const exponential_distribution<_RealType>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    return __os << __x.lambda();
+}
+
+template <class _CharT, class _Traits, class _RealType>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           exponential_distribution<_RealType>& __x)
+{
+    typedef exponential_distribution<_RealType> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    result_type __lambda;
+    __is >> __lambda;
+    if (!__is.fail())
+        __x.param(param_type(__lambda));
+    return __is;
+}
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_RANDOM

Modified: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp?rev=103621&r1=103620&r2=103621&view=diff
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp (original)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp Wed May 12 12:08:57 2010
@@ -17,8 +17,6 @@
 #include <random>
 #include <cassert>
 
-#include <iostream>
-
 int main()
 {
     {

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/assign.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// exponential_distribution& operator=(const exponential_distribution&);
+
+#include <random>
+#include <cassert>
+
+void
+test1()
+{
+    typedef std::exponential_distribution<> D;
+    D d1(0.75);
+    D d2;
+    assert(d1 != d2);
+    d2 = d1;
+    assert(d1 == d2);
+}
+
+int main()
+{
+    test1();
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/copy.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// exponential_distribution(const exponential_distribution&);
+
+#include <random>
+#include <cassert>
+
+void
+test1()
+{
+    typedef std::exponential_distribution<> D;
+    D d1(1.75);
+    D d2 = d1;
+    assert(d1 == d2);
+}
+
+int main()
+{
+    test1();
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_double.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// explicit exponential_distribution(RealType lambda = 1.0);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        D d;
+        assert(d.lambda() == 1);
+    }
+    {
+        typedef std::exponential_distribution<> D;
+        D d(3.5);
+        assert(d.lambda() == 3.5);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/ctor_param.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// explicit exponential_distribution(const param_type& parm);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type P;
+        P p(0.25);
+        D d(p);
+        assert(d.lambda() == 0.25);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eq.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// bool operator=(const exponential_distribution& x,
+//                const exponential_distribution& y);
+// bool operator!(const exponential_distribution& x,
+//                const exponential_distribution& y);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        D d1(.25);
+        D d2(.25);
+        assert(d1 == d2);
+    }
+    {
+        typedef std::exponential_distribution<> D;
+        D d1(.28);
+        D d2(.25);
+        assert(d1 != d2);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// template<class _URNG> result_type operator()(_URNG& g);
+
+#include <random>
+#include <cassert>
+#include <vector>
+#include <numeric>
+
+template <class T>
+inline
+T
+sqr(T x)
+{
+    return x * x;
+}
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type P;
+        typedef std::knuth_b G;
+        G g;
+        D d(.75);
+        const int N = 1000;
+        std::vector<D::result_type> u;
+        for (int i = 0; i < N; ++i)
+            u.push_back(d(g));
+        D::result_type mean = std::accumulate(u.begin(), u.end(),
+                                              D::result_type(0)) / u.size();
+        D::result_type var = 0;
+        for (int i = 0; i < u.size(); ++i)
+            var += sqr(u[i] - mean);
+        var /= u.size();
+        D::result_type x_mean = 1/d.lambda();
+        D::result_type x_var = 1/sqr(d.lambda());
+        assert(std::abs(mean - x_mean) / x_mean < 0.01);
+        assert(std::abs(var - x_var) / x_var < 0.01);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/eval_param.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
+
+#include <random>
+#include <cassert>
+#include <vector>
+#include <numeric>
+
+template <class T>
+inline
+T
+sqr(T x)
+{
+    return x * x;
+}
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type P;
+        typedef std::knuth_b G;
+        G g;
+        D d(.75);
+        P p(2);
+        const int N = 1000;
+        std::vector<D::result_type> u;
+        for (int i = 0; i < N; ++i)
+            u.push_back(d(g, p));
+        D::result_type mean = std::accumulate(u.begin(), u.end(),
+                                              D::result_type(0)) / u.size();
+        D::result_type var = 0;
+        for (int i = 0; i < u.size(); ++i)
+            var += sqr(u[i] - mean);
+        var /= u.size();
+        D::result_type x_mean = 1/p.lambda();
+        D::result_type x_var = 1/sqr(p.lambda());
+        assert(std::abs(mean - x_mean) / x_mean < 0.01);
+        assert(std::abs(var - x_var) / x_var < 0.01);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/get_param.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// param_type param() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type P;
+        P p(.125);
+        D d(p);
+        assert(d.param() == p);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/io.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// template <class CharT, class Traits, class RealType>
+// basic_ostream<CharT, Traits>&
+// operator<<(basic_ostream<CharT, Traits>& os,
+//            const exponential_distribution<RealType>& x);
+
+// template <class CharT, class Traits, class RealType>
+// basic_istream<CharT, Traits>&
+// operator>>(basic_istream<CharT, Traits>& is,
+//            exponential_distribution<RealType>& x);
+
+#include <random>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        D d1(7);
+        std::ostringstream os;
+        os << d1;
+        std::istringstream is(os.str());
+        D d2;
+        is >> d2;
+        assert(d1 == d2);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/max.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// result_type max() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        D d(.25);
+        D::result_type m = d.max();
+        assert(146 < m && m < 147);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/min.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+
+// result_type min() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        D d(.5);
+        assert(d.min() == 0);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_assign.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p0(.7);
+        param_type p;
+        p = p0;
+        assert(p.lambda() == .7);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_copy.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p0(.125);
+        param_type p = p0;
+        assert(p.lambda() == .125);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_ctor.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p;
+        assert(p.lambda() == 1);
+    }
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p(10);
+        assert(p.lambda() == 10);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_eq.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p1(0.75);
+        param_type p2(0.75);
+        assert(p1 == p2);
+    }
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p1(0.75);
+        param_type p2(0.5);
+        assert(p1 != p2);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/param_types.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <type_traits>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type param_type;
+        typedef param_type::distribution_type distribution_type;
+        static_assert((std::is_same<D, distribution_type>::value), "");
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_param.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/set_param.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution;
+
+// void param(const param_type& parm);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::param_type P;
+        P p(0.25);
+        D d(0.75);
+        d.param(p);
+        assert(d.param() == p);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp?rev=103621&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/types.pass.cpp Wed May 12 12:08:57 2010
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class exponential_distribution
+// {
+// public:
+//     // types
+//     typedef RealType result_type;
+
+#include <random>
+#include <type_traits>
+
+int main()
+{
+    {
+        typedef std::exponential_distribution<> D;
+        typedef D::result_type result_type;
+        static_assert((std::is_same<result_type, double>::value), "");
+    }
+    {
+        typedef std::exponential_distribution<float> D;
+        typedef D::result_type result_type;
+        static_assert((std::is_same<result_type, float>::value), "");
+    }
+}





More information about the cfe-commits mailing list