[libc++] Avoid implicit conversion warning in a <random> test

By stashing the computation of `E::max() - E::min()` in a variable, we
avoid the warning introduced in r367497. Note that we use `auto` to
avoid having to deduce the type of the computation, which is not a
problem since Clang provides `auto` as an extension even in C++03 (and
we disable warnings related to using C++11 extensions in the test suite).

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@369429 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Louis Dionne 2019-08-20 19:28:26 +00:00
parent 61563aa43f
commit 76dbc2cb72

View File

@ -19,85 +19,78 @@
int main(int, char**)
{
typedef std::minstd_rand0 E;
auto range = E::max() - E::min();
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, 0>(r);
assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
assert(f == truncate_fp((16807 - E::min()) / (range + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, 1>(r);
assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
assert(f == truncate_fp((16807 - E::min()) / (range + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits - 1>(r);
assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
assert(f == truncate_fp((16807 - E::min()) / (range + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits>(r);
assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
assert(f == truncate_fp((16807 - E::min()) / (range + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef float F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits + 1>(r);
assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
assert(f == truncate_fp((16807 - E::min()) / (range + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, 0>(r);
assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
assert(f == truncate_fp((16807 - E::min()) / (range + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, 1>(r);
assert(f == truncate_fp((16807 - E::min()) / (E::max() - E::min() + F(1))));
assert(f == truncate_fp((16807 - E::min()) / (range + F(1))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits - 1>(r);
assert(f == truncate_fp(
(16807 - E::min() +
(282475249 - E::min()) * (E::max() - E::min() + F(1))) /
((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))));
(282475249 - E::min()) * (range + F(1))) /
((range + F(1)) * (range + F(1)))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits>(r);
assert(f == truncate_fp(
(16807 - E::min() +
(282475249 - E::min()) * (E::max() - E::min() + F(1))) /
((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))));
(282475249 - E::min()) * (range + F(1))) /
((range + F(1)) * (range + F(1)))));
}
{
typedef std::minstd_rand0 E;
typedef double F;
E r;
F f = std::generate_canonical<F, std::numeric_limits<F>::digits + 1>(r);
assert(f == truncate_fp(
(16807 - E::min() +
(282475249 - E::min()) * (E::max() - E::min() + F(1))) /
((E::max() - E::min() + F(1)) * (E::max() - E::min() + F(1)))));
(282475249 - E::min()) * (range + F(1))) /
((range + F(1)) * (range + F(1)))));
}
return 0;