Skip to content

Commit 8bc3105

Browse files
committed
fix(hexfloat): extraneous '.' when no exponent, ParseHex should handle specials
1 parent 1deceec commit 8bc3105

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/literal.cc

+18-5
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ template <typename T>
253253
Result FloatParser<T>::ParseHex(const char* s,
254254
const char* end,
255255
Uint* out_bits) {
256+
if ((end - s >= 3 && strncmp(s, "inf", 3) == 0) ||
257+
(end - s >= 4 && strncmp(s, "-inf", 4) == 0)) {
258+
ParseInfinity(s, end, out_bits);
259+
return Result::Ok;
260+
}
261+
if ((end - s >= 3 && strncmp(s, "nan", 3) == 0) ||
262+
(end - s >= 4 && strncmp(s, "nan:", 4) == 0)) {
263+
ParseNan(s, end, out_bits);
264+
return Result::Ok;
265+
}
266+
256267
bool is_neg = false;
257268
if (*s == '-') {
258269
is_neg = true;
@@ -515,11 +526,13 @@ void FloatWriter<T>::WriteHex(char* out, size_t size, Uint bits) {
515526
exp -= leading_zeroes;
516527
}
517528

518-
*p++ = '.';
519-
while (sig) {
520-
int nybble = (sig >> kTopNybbleShift) & 0xf;
521-
*p++ = s_hex_digits[nybble];
522-
sig <<= 4;
529+
if (sig) {
530+
*p++ = '.';
531+
while (sig) {
532+
int nybble = (sig >> kTopNybbleShift) & 0xf;
533+
*p++ = s_hex_digits[nybble];
534+
sig <<= 4;
535+
}
523536
}
524537
}
525538
*p++ = 'p';

0 commit comments

Comments
 (0)