@@ -65,6 +65,8 @@ struct FloatTraits;
6565
6666template <>
6767struct FloatTraits <double > {
68+ using mantissa_t = uint64_t ;
69+
6870 // The number of mantissa bits in the given float type. This includes the
6971 // implied high bit.
7072 static constexpr int kTargetMantissaBits = 53 ;
@@ -103,7 +105,7 @@ struct FloatTraits<double> {
103105 // a normal value is made, or it must be less narrow than that, in which case
104106 // `exponent` must be exactly kMinNormalExponent, and a subnormal value is
105107 // made.
106- static double Make (uint64_t mantissa, int exponent, bool sign) {
108+ static double Make (mantissa_t mantissa, int exponent, bool sign) {
107109#ifndef ABSL_BIT_PACK_FLOATS
108110 // Support ldexp no matter which namespace it's in. Some platforms
109111 // incorrectly don't put it in namespace std.
@@ -116,8 +118,10 @@ struct FloatTraits<double> {
116118 if (mantissa > kMantissaMask ) {
117119 // Normal value.
118120 // Adjust by 1023 for the exponent representation bias, and an additional
119- // 52 due to the implied decimal point in the IEEE mantissa represenation.
120- dbl += uint64_t {exponent + 1023u + kTargetMantissaBits - 1 } << 52 ;
121+ // 52 due to the implied decimal point in the IEEE mantissa
122+ // representation.
123+ dbl += static_cast <uint64_t >(exponent + 1023 + kTargetMantissaBits - 1 )
124+ << 52 ;
121125 mantissa &= kMantissaMask ;
122126 } else {
123127 // subnormal value
@@ -134,16 +138,20 @@ struct FloatTraits<double> {
134138// members and methods.
135139template <>
136140struct FloatTraits <float > {
141+ using mantissa_t = uint32_t ;
142+
137143 static constexpr int kTargetMantissaBits = 24 ;
138144 static constexpr int kMaxExponent = 104 ;
139145 static constexpr int kMinNormalExponent = -149 ;
146+
140147 static float MakeNan (const char * tagp) {
141148 // Support nanf no matter which namespace it's in. Some platforms
142149 // incorrectly don't put it in namespace std.
143150 using namespace std ; // NOLINT
144151 return nanf (tagp);
145152 }
146- static float Make (uint32_t mantissa, int exponent, bool sign) {
153+
154+ static float Make (mantissa_t mantissa, int exponent, bool sign) {
147155#ifndef ABSL_BIT_PACK_FLOATS
148156 // Support ldexpf no matter which namespace it's in. Some platforms
149157 // incorrectly don't put it in namespace std.
@@ -157,7 +165,8 @@ struct FloatTraits<float> {
157165 // Normal value.
158166 // Adjust by 127 for the exponent representation bias, and an additional
159167 // 23 due to the implied decimal point in the IEEE mantissa represenation.
160- flt += uint32_t {exponent + 127u + kTargetMantissaBits - 1 } << 23 ;
168+ flt += static_cast <uint32_t >(exponent + 127 + kTargetMantissaBits - 1 )
169+ << 23 ;
161170 mantissa &= kMantissaMask ;
162171 } else {
163172 // subnormal value
@@ -242,9 +251,9 @@ struct CalculatedFloat {
242251
243252// Returns the bit width of the given uint128. (Equivalently, returns 128
244253// minus the number of leading zero bits.)
245- unsigned BitWidth (uint128 value) {
254+ int BitWidth (uint128 value) {
246255 if (Uint128High64 (value) == 0 ) {
247- return static_cast < unsigned >( bit_width (Uint128Low64 (value) ));
256+ return bit_width (Uint128Low64 (value));
248257 }
249258 return 128 - countl_zero (Uint128High64 (value));
250259}
@@ -337,8 +346,10 @@ void EncodeResult(const CalculatedFloat& calculated, bool negative,
337346 *value = negative ? -0.0 : 0.0 ;
338347 return ;
339348 }
340- *value = FloatTraits<FloatType>::Make (calculated.mantissa ,
341- calculated.exponent , negative);
349+ *value = FloatTraits<FloatType>::Make (
350+ static_cast <typename FloatTraits<FloatType>::mantissa_t >(
351+ calculated.mantissa ),
352+ calculated.exponent , negative);
342353}
343354
344355// Returns the given uint128 shifted to the right by `shift` bits, and rounds
@@ -519,7 +530,7 @@ CalculatedFloat CalculateFromParsedHexadecimal(
519530 const strings_internal::ParsedFloat& parsed_hex) {
520531 uint64_t mantissa = parsed_hex.mantissa ;
521532 int exponent = parsed_hex.exponent ;
522- auto mantissa_width = static_cast < unsigned >( bit_width (mantissa) );
533+ int mantissa_width = bit_width (mantissa);
523534 const int shift = NormalizedShiftSize<FloatType>(mantissa_width, exponent);
524535 bool result_exact;
525536 exponent += shift;
0 commit comments