From ab01e0403a40813857a8e580d9cf1580ba0c4139 Mon Sep 17 00:00:00 2001 From: Leonhard Markert Date: Fri, 6 Aug 2021 15:21:35 +0200 Subject: Simplifies the construction of the value returned by GenerateRealFromBits() (#994) * GenerateRealFromBits: sign is already set If std::is_same::value then sign is already set to zero thanks to: uint_type sign = std::is_same::value ? (static_cast(1) << (kUintBits - 1)) : 0; // <- here So the conditional is unnecessary. * Update generate_real.h Remove extra parenthesis Co-authored-by: Derek Mauro <761129+derekmauro@users.noreply.github.com> --- absl/random/internal/generate_real.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'absl') diff --git a/absl/random/internal/generate_real.h b/absl/random/internal/generate_real.h index 4f62873d..d5fbb44c 100644 --- a/absl/random/internal/generate_real.h +++ b/absl/random/internal/generate_real.h @@ -127,10 +127,8 @@ inline RealType GenerateRealFromBits(uint64_t bits, int exp_bias = 0) { // Construct the 32-bit or 64-bit IEEE 754 floating-point value from // the individual fields: sign, exp, mantissa(bits). - uint_type val = - (std::is_same::value ? 0u : sign) | - (static_cast(exp) << kExp) | - (static_cast(bits) & kMask); + uint_type val = sign | (static_cast(exp) << kExp) | + (static_cast(bits) & kMask); // bit_cast to the output-type real_type result; -- cgit v1.2.3