diff options
author | Abseil Team <absl-team@google.com> | 2021-02-07 17:35:10 -0800 |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2021-02-08 13:24:45 -0500 |
commit | c36d825d9a5443f81d2656685ae021d6326da90c (patch) | |
tree | da1bc21f837193a9a763132d219afa84aa74cead /absl/random/internal/randen_engine.h | |
parent | 9c6a50fdd80bb39fabd95faeda84f04062685ff3 (diff) |
Export of internal Abseil changes
--
756156bf03da050e8b27539a8247d9af7e44c6a2 by Abseil Team <absl-team@google.com>:
Fix a typo in cord.h: "accomodate" => "accommodate"
PiperOrigin-RevId: 356168875
--
638befdb342b608ec28910ee931ee200fdbe1fef by Samuel Benzaquen <sbenza@google.com>:
Fix float conversion for PPC.
In PPC `long double` is a double-double representation which behaves weirdly
wrt numeric_limits. Don't take `long double` into account when we are not
handling `long double` natively anyway.
Fix the convert test to always run the conversion even if we are not going to
compare against libc's printf result. This allows exercising the code itself to
make sure we don't trigger assertions or UB found by sanitizers.
PiperOrigin-RevId: 355857729
--
ff5f893319fa76b273c7785b76ef6c95b1791076 by Abseil Team <absl-team@google.com>:
Example usage tweak
PiperOrigin-RevId: 355695750
--
0efc454f90023fa651b226e5e3ba7395a3b60c6d by Benjamin Barenblat <bbaren@google.com>:
Remove endian-sensitivity from Abseil’s RNG
Ensure that the Abseil random number generator produces identical output
on both big- and little-endian platforms by byte-swapping appropriately
on big-endian systems.
PiperOrigin-RevId: 355635051
GitOrigin-RevId: 756156bf03da050e8b27539a8247d9af7e44c6a2
Change-Id: Iaaa69767b8e85d626742b9ba56fefb75f07c69ee
Diffstat (limited to 'absl/random/internal/randen_engine.h')
-rw-r--r-- | absl/random/internal/randen_engine.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/absl/random/internal/randen_engine.h b/absl/random/internal/randen_engine.h index 6b337313..92bb8905 100644 --- a/absl/random/internal/randen_engine.h +++ b/absl/random/internal/randen_engine.h @@ -23,6 +23,7 @@ #include <limits> #include <type_traits> +#include "absl/base/internal/endian.h" #include "absl/meta/type_traits.h" #include "absl/random/internal/iostream_state_saver.h" #include "absl/random/internal/randen.h" @@ -76,7 +77,7 @@ class alignas(16) randen_engine { impl_.Generate(state_); } - return state_[next_++]; + return little_endian::ToHost(state_[next_++]); } template <class SeedSequence> @@ -181,7 +182,8 @@ class alignas(16) randen_engine { // In the case that `elem` is `uint8_t`, it must be cast to something // larger so that it prints as an integer rather than a character. For // simplicity, apply the cast all circumstances. - os << static_cast<numeric_type>(elem) << os.fill(); + os << static_cast<numeric_type>(little_endian::FromHost(elem)) + << os.fill(); } os << engine.next_; return os; @@ -200,7 +202,7 @@ class alignas(16) randen_engine { // necessary to read a wider type and then cast it to uint8_t. numeric_type value; is >> value; - elem = static_cast<result_type>(value); + elem = little_endian::ToHost(static_cast<result_type>(value)); } is >> next; if (is.fail()) { |