aboutsummaryrefslogtreecommitdiff
path: root/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/abseil-cpp/absl/random/exponential_distribution_test.cc')
-rw-r--r--third_party/abseil-cpp/absl/random/exponential_distribution_test.cc48
1 files changed, 23 insertions, 25 deletions
diff --git a/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc b/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
index 81a5d17bac..f3cfd76442 100644
--- a/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
+++ b/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
@@ -15,7 +15,6 @@
#include "absl/random/exponential_distribution.h"
#include <algorithm>
-#include <cfloat>
#include <cmath>
#include <cstddef>
#include <cstdint>
@@ -31,10 +30,8 @@
#include "gtest/gtest.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/macros.h"
-#include "absl/numeric/internal/representation.h"
#include "absl/random/internal/chi_square.h"
#include "absl/random/internal/distribution_test_util.h"
-#include "absl/random/internal/pcg_engine.h"
#include "absl/random/internal/sequence_urbg.h"
#include "absl/random/random.h"
#include "absl/strings/str_cat.h"
@@ -49,15 +46,11 @@ using absl::random_internal::kChiSquared;
template <typename RealType>
class ExponentialDistributionTypedTest : public ::testing::Test {};
-// double-double arithmetic is not supported well by either GCC or Clang; see
-// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99048,
-// https://bugs.llvm.org/show_bug.cgi?id=49131, and
-// https://bugs.llvm.org/show_bug.cgi?id=49132. Don't bother running these tests
-// with double doubles until compiler support is better.
-using RealTypes =
- std::conditional<absl::numeric_internal::IsDoubleDouble(),
- ::testing::Types<float, double>,
- ::testing::Types<float, double, long double>>::type;
+#if defined(__EMSCRIPTEN__)
+using RealTypes = ::testing::Types<float, double>;
+#else
+using RealTypes = ::testing::Types<float, double, long double>;
+#endif // defined(__EMSCRIPTEN__)
TYPED_TEST_CASE(ExponentialDistributionTypedTest, RealTypes);
TYPED_TEST(ExponentialDistributionTypedTest, SerializeTest) {
@@ -136,6 +129,23 @@ TYPED_TEST(ExponentialDistributionTypedTest, SerializeTest) {
ss >> after;
+#if defined(__powerpc64__) || defined(__PPC64__) || defined(__powerpc__) || \
+ defined(__ppc__) || defined(__PPC__)
+ if (std::is_same<TypeParam, long double>::value) {
+ // Roundtripping floating point values requires sufficient precision to
+ // reconstruct the exact value. It turns out that long double has some
+ // errors doing this on ppc, particularly for values
+ // near {1.0 +/- epsilon}.
+ if (lambda <= std::numeric_limits<double>::max() &&
+ lambda >= std::numeric_limits<double>::lowest()) {
+ EXPECT_EQ(static_cast<double>(before.lambda()),
+ static_cast<double>(after.lambda()))
+ << ss.str();
+ }
+ continue;
+ }
+#endif
+
EXPECT_EQ(before.lambda(), after.lambda()) //
<< ss.str() << " " //
<< (ss.good() ? "good " : "") //
@@ -195,10 +205,7 @@ class ExponentialDistributionTests : public testing::TestWithParam<Param>,
template <typename D>
double SingleChiSquaredTest();
- // We use a fixed bit generator for distribution accuracy tests. This allows
- // these tests to be deterministic, while still testing the qualify of the
- // implementation.
- absl::random_internal::pcg64_2018_engine rng_{0x2B7E151628AED2A6};
+ absl::InsecureBitGen rng_;
};
template <typename D>
@@ -385,15 +392,6 @@ TEST(ExponentialDistributionTest, StabilityTest) {
TEST(ExponentialDistributionTest, AlgorithmBounds) {
// Relies on absl::uniform_real_distribution, so some of these comments
// reference that.
-
-#if (defined(__i386__) || defined(_M_IX86)) && FLT_EVAL_METHOD != 0
- // We're using an x87-compatible FPU, and intermediate operations can be
- // performed with 80-bit floats. This produces slightly different results from
- // what we expect below.
- GTEST_SKIP()
- << "Skipping the test because we detected x87 floating-point semantics";
-#endif
-
absl::exponential_distribution<double> dist;
{