[libc++] Fix broken <random> test

In r369429, I hoisted a floating point computation to a variable in order
to remove a warning. However, it turns out this doesn't play well with
floating point arithmetic. This commit reverts r369429 and instead casts
the result of the floating point computation to remove the warning.

Whether hoisting the computaiton to a variable should give the same
result can be investigated independently.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@369693 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp b/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp
index b5050a5..047eb5e 100644
--- a/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp
+++ b/test/std/numerics/rand/rand.util/rand.util.canonical/generate_canonical.pass.cpp
@@ -19,78 +19,85 @@
 
 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()) / (range + F(1))));
+        assert(f == truncate_fp((16807 - E::min()) / (static_cast<F>(E::max() - E::min()) + 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()) / (range + F(1))));
+        assert(f == truncate_fp((16807 - E::min()) / (static_cast<F>(E::max() - E::min()) + 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()) / (range + F(1))));
+        assert(f == truncate_fp((16807 - E::min()) / (static_cast<F>(E::max() - E::min()) + 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()) / (range + F(1))));
+        assert(f == truncate_fp((16807 - E::min()) / (static_cast<F>(E::max() - E::min()) + 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()) / (range + F(1))));
+        assert(f == truncate_fp((16807 - E::min()) / (static_cast<F>(E::max() - E::min()) + 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()) / (range + F(1))));
+        assert(f == truncate_fp((16807 - E::min()) / (static_cast<F>(E::max() - E::min()) + 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()) / (range + F(1))));
+        assert(f == truncate_fp((16807 - E::min()) / (static_cast<F>(E::max() - E::min()) + 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()) * (range + F(1))) /
-            ((range + F(1)) * (range + F(1)))));
+            (282475249 - E::min()) * (static_cast<F>(E::max() - E::min()) + F(1))) /
+            ((static_cast<F>(E::max() - E::min()) + F(1)) * (static_cast<F>(E::max() - E::min()) + 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()) * (range + F(1))) /
-            ((range + F(1)) * (range + F(1)))));
+            (282475249 - E::min()) * (static_cast<F>(E::max() - E::min()) + F(1))) /
+            ((static_cast<F>(E::max() - E::min()) + F(1)) * (static_cast<F>(E::max() - E::min()) + 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()) * (range + F(1))) /
-            ((range + F(1)) * (range + F(1)))));
+            (282475249 - E::min()) * (static_cast<F>(E::max() - E::min()) + F(1))) /
+            ((static_cast<F>(E::max() - E::min()) + F(1)) * (static_cast<F>(E::max() - E::min()) + F(1)))));
     }
 
   return 0;