Simplifies the construction of the value returned by GenerateRealFromBits() (#994)

* GenerateRealFromBits: sign is already set

If std::is_same<SignedTag, GeneratePositiveTag>::value then sign is
already set to zero thanks to:

    uint_type sign = std::is_same<SignedTag, GenerateNegativeTag>::value
                         ? (static_cast<uint_type>(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>
pull/998/head
Leonhard Markert 3 years ago committed by GitHub
parent ee0ebdae4a
commit ab01e0403a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      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<SignedTag, GeneratePositiveTag>::value ? 0u : sign) |
(static_cast<uint_type>(exp) << kExp) |
(static_cast<uint_type>(bits) & kMask);
uint_type val = sign | (static_cast<uint_type>(exp) << kExp) |
(static_cast<uint_type>(bits) & kMask);
// bit_cast to the output-type
real_type result;

Loading…
Cancel
Save