| ... | @@ -1124,6 +1124,7 @@ pub fn formatFloatHexadecimal( | ... | @@ -1124,6 +1124,7 @@ pub fn formatFloatHexadecimal( |
| 1124 | const TU = std.meta.Int(.unsigned, std.meta.bitCount(T)); | 1124 | const TU = std.meta.Int(.unsigned, std.meta.bitCount(T)); |
| 1125 | | 1125 | |
| 1126 | const mantissa_bits = math.floatMantissaBits(T); | 1126 | const mantissa_bits = math.floatMantissaBits(T); |
| | 1127 | const fractional_bits = math.floatFractionalBits(T); |
| 1127 | const exponent_bits = math.floatExponentBits(T); | 1128 | const exponent_bits = math.floatExponentBits(T); |
| 1128 | const mantissa_mask = (1 << mantissa_bits) - 1; | 1129 | const mantissa_mask = (1 << mantissa_bits) - 1; |
| 1129 | const exponent_mask = (1 << exponent_bits) - 1; | 1130 | const exponent_mask = (1 << exponent_bits) - 1; |
| ... | @@ -1155,14 +1156,14 @@ pub fn formatFloatHexadecimal( | ... | @@ -1155,14 +1156,14 @@ pub fn formatFloatHexadecimal( |
| 1155 | // Adjust the exponent for printing. | 1156 | // Adjust the exponent for printing. |
| 1156 | exponent += 1; | 1157 | exponent += 1; |
| 1157 | } else { | 1158 | } else { |
| 1158 | // Add the implicit 1. | 1159 | if (fractional_bits == mantissa_bits) |
| 1159 | mantissa |= 1 << mantissa_bits; | 1160 | mantissa |= 1 << fractional_bits; // Add the implicit integer bit. |
| 1160 | } | 1161 | } |
| 1161 | | 1162 | |
| 1162 | // Fill in zeroes to round the mantissa width to a multiple of 4. | 1163 | // Fill in zeroes to round the mantissa width to a multiple of 4. |
| 1163 | if (T == f16) mantissa <<= 2 else if (T == f32) mantissa <<= 1; | 1164 | if (T == f16) mantissa <<= 2 else if (T == f32) mantissa <<= 1; |
| 1164 | | 1165 | |
| 1165 | const mantissa_digits = (mantissa_bits + 3) / 4; | 1166 | const mantissa_digits = (fractional_bits + 3) / 4; |
| 1166 | | 1167 | |
| 1167 | if (options.precision) |precision| { | 1168 | if (options.precision) |precision| { |
| 1168 | // Round if needed. | 1169 | // Round if needed. |