diff options
author | Benjamin Barenblat <bbaren@google.com> | 2021-06-29 22:15:35 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2021-06-29 22:15:35 -0400 |
commit | ab52b3b9670a5bb555c148d9d5638a1a7fa3e877 (patch) | |
tree | 92220c11d51433d07f6841e9219a9b31fba8c8e4 /debian/patches | |
parent | 2ac260f98e9659b523d6eae58fa76bf5f6366fe9 (diff) |
Add patch to explicitly round float multiplication
Add a call to rint in a test, ensuring it passes on the x87.
Diffstat (limited to 'debian/patches')
-rw-r--r-- | debian/patches/missing-rint.diff | 45 | ||||
-rw-r--r-- | debian/patches/series | 1 |
2 files changed, 46 insertions, 0 deletions
diff --git a/debian/patches/missing-rint.diff b/debian/patches/missing-rint.diff new file mode 100644 index 00000000..d9865364 --- /dev/null +++ b/debian/patches/missing-rint.diff @@ -0,0 +1,45 @@ +From: Benjamin Barenblat <bbaren@google.com> +Subject: Round a double multiplication before casting it to integer +Forwarded: yes +Applied-Upstream: https://github.com/abseil/abseil-cpp/commit/60be12ed9822078970f05f3c560324184302df6b + +The code + + static_cast<int>(x * y) + +(for double x and y) performs a double multiplication into a temporary +that, by standard, may have excess precision. The subsequent cast to int +discards the excess precision. However, the cast may examine the excess +precision during conversion, producing surprising results like + + static_cast<int>(1.7 * 10) == 16 + +on certain systems. Correct this case by explicitly rounding 1.7 * 10 +before casting it. + +The author works at Google. Upstream applied this patch as Piper +revision 378922064 and exported it to GitHub; the Applied-Upstream URL +above points to the exported commit. + +--- a/absl/random/mocking_bit_gen_test.cc ++++ b/absl/random/mocking_bit_gen_test.cc +@@ -15,6 +15,7 @@ + // + #include "absl/random/mocking_bit_gen.h" + ++#include <cmath> + #include <numeric> + #include <random> + +@@ -328,8 +329,9 @@ TEST(BasicMocking, WillByDefaultWithArgs) { + + absl::MockingBitGen gen; + ON_CALL(absl::MockPoisson<int>(), Call(gen, _)) +- .WillByDefault( +- [](double lambda) { return static_cast<int>(lambda * 10); }); ++ .WillByDefault([](double lambda) { ++ return static_cast<int>(std::rint(lambda * 10)); ++ }); + EXPECT_EQ(absl::Poisson<int>(gen, 1.7), 17); + EXPECT_EQ(absl::Poisson<int>(gen, 0.03), 0); + } diff --git a/debian/patches/series b/debian/patches/series index 99f5ccbc..9cca595d 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -6,3 +6,4 @@ thumb-function-bounds.diff float-rounding.diff DiscreteDistributionTest-irrelevant-destination-buckets.diff float-tests-disable-i386.diff +missing-rint.diff |