1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<class RealType, size_t bits, class URNG>
12 // RealType generate_canonical(URNG& g);
19 #include "test_macros.h"
20 #include "truncate_fp.h"
25 typedef std::minstd_rand0 E
;
28 F f
= std::generate_canonical
<F
, 0>(r
);
29 assert(f
== truncate_fp((16807 - E::min()) / (static_cast<F
>(E::max() - E::min()) + F(1))));
32 typedef std::minstd_rand0 E
;
35 F f
= std::generate_canonical
<F
, 1>(r
);
36 assert(f
== truncate_fp((16807 - E::min()) / (static_cast<F
>(E::max() - E::min()) + F(1))));
39 typedef std::minstd_rand0 E
;
42 F f
= std::generate_canonical
<F
, std::numeric_limits
<F
>::digits
- 1>(r
);
43 assert(f
== truncate_fp((16807 - E::min()) / (static_cast<F
>(E::max() - E::min()) + F(1))));
46 typedef std::minstd_rand0 E
;
49 F f
= std::generate_canonical
<F
, std::numeric_limits
<F
>::digits
>(r
);
50 assert(f
== truncate_fp((16807 - E::min()) / (static_cast<F
>(E::max() - E::min()) + F(1))));
53 typedef std::minstd_rand0 E
;
56 F f
= std::generate_canonical
<F
, std::numeric_limits
<F
>::digits
+ 1>(r
);
57 assert(f
== truncate_fp((16807 - E::min()) / (static_cast<F
>(E::max() - E::min()) + F(1))));
61 typedef std::minstd_rand0 E
;
64 F f
= std::generate_canonical
<F
, 0>(r
);
65 assert(f
== truncate_fp((16807 - E::min()) / (static_cast<F
>(E::max() - E::min()) + F(1))));
68 typedef std::minstd_rand0 E
;
71 F f
= std::generate_canonical
<F
, 1>(r
);
72 assert(f
== truncate_fp((16807 - E::min()) / (static_cast<F
>(E::max() - E::min()) + F(1))));
75 typedef std::minstd_rand0 E
;
78 F f
= std::generate_canonical
<F
, std::numeric_limits
<F
>::digits
- 1>(r
);
79 assert(f
== truncate_fp(
81 (282475249 - E::min()) * (static_cast<F
>(E::max() - E::min()) + F(1))) /
82 ((static_cast<F
>(E::max() - E::min()) + F(1)) * (static_cast<F
>(E::max() - E::min()) + F(1)))));
85 typedef std::minstd_rand0 E
;
88 F f
= std::generate_canonical
<F
, std::numeric_limits
<F
>::digits
>(r
);
89 assert(f
== truncate_fp(
91 (282475249 - E::min()) * (static_cast<F
>(E::max() - E::min()) + F(1))) /
92 ((static_cast<F
>(E::max() - E::min()) + F(1)) * (static_cast<F
>(E::max() - E::min()) + F(1)))));
95 typedef std::minstd_rand0 E
;
98 F f
= std::generate_canonical
<F
, std::numeric_limits
<F
>::digits
+ 1>(r
);
99 assert(f
== truncate_fp(
101 (282475249 - E::min()) * (static_cast<F
>(E::max() - E::min()) + F(1))) /
102 ((static_cast<F
>(E::max() - E::min()) + F(1)) * (static_cast<F
>(E::max() - E::min()) + F(1)))));