[lld] BPSectionOrderer: stabilize iteration order with MapVector
[llvm-project.git] / libcxx / test / std / numerics / rand / rand.dist / rand.dist.norm / rand.dist.norm.cauchy / eval.pass.cpp
blob83e64046f0dcde0b8e8398008259770759307f47
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // REQUIRES: long_tests
11 // <random>
13 // template<class RealType = double>
14 // class cauchy_distribution
16 // template<class _URNG> result_type operator()(_URNG& g);
18 #include <random>
20 #include <cassert>
21 #include <cmath>
22 #include <vector>
23 #include <algorithm>
25 #include "test_macros.h"
27 double
28 f(double x, double a, double b)
30 return 1/3.1415926535897932 * std::atan((x - a)/b) + .5;
33 int main(int, char**)
36 typedef std::cauchy_distribution<> D;
37 typedef std::mt19937 G;
38 G g;
39 const double a = 10;
40 const double b = .5;
41 D d(a, b);
42 const int N = 1000000;
43 std::vector<D::result_type> u;
44 for (int i = 0; i < N; ++i)
45 u.push_back(d(g));
46 std::sort(u.begin(), u.end());
47 for (int i = 0; i < N; ++i)
48 assert(std::abs(f(u[i], a, b) - double(i) / N) < .0013);
51 typedef std::cauchy_distribution<> D;
52 typedef std::mt19937 G;
53 G g;
54 const double a = -1.5;
55 const double b = 1;
56 D d(a, b);
57 const int N = 1000000;
58 std::vector<D::result_type> u;
59 for (int i = 0; i < N; ++i)
60 u.push_back(d(g));
61 std::sort(u.begin(), u.end());
62 for (int i = 0; i < N; ++i)
63 assert(std::abs(f(u[i], a, b) - double(i) / N) < .0013);
66 typedef std::cauchy_distribution<> D;
67 typedef std::mt19937 G;
68 G g;
69 const double a = .5;
70 const double b = 2;
71 D d(a, b);
72 const int N = 1000000;
73 std::vector<D::result_type> u;
74 for (int i = 0; i < N; ++i)
75 u.push_back(d(g));
76 std::sort(u.begin(), u.end());
77 for (int i = 0; i < N; ++i)
78 assert(std::abs(f(u[i], a, b) - double(i) / N) < .0013);
81 return 0;