authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2025-06-08 14:32:16+12:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-06-08 17:57:37-04:00
logcffa98eef54568bf43cbbe14a3cbbf972a2c7a7a
tree805c9325a460680e752d469fe04337026221d73a
parent201c0f54a597a53d04c782687c903cd5ea177066

std.fmt.parseFloat: fix hex-float negative inf

Closes #24111.

2 files changed, 4 insertions(+), 1 deletions(-)

lib/std/fmt/parse_float.zig+3
......@@ -159,6 +159,9 @@ test "hex.special" {
159159 try testing.expect(math.isPositiveInf(try parseFloat(f32, "iNf")));
160160 try testing.expect(math.isPositiveInf(try parseFloat(f32, "+Inf")));
161161 try testing.expect(math.isNegativeInf(try parseFloat(f32, "-iNf")));
162
163 try testing.expect(math.isPositiveInf(try parseFloat(f32, "0x9999p9999")));
164 try testing.expect(math.isNegativeInf(try parseFloat(f32, "-0x9999p9999")));
162165}
163166
164167test "hex.zero" {
lib/std/fmt/parse_float/convert_hex.zig+1-1
......@@ -78,7 +78,7 @@ pub fn convertHex(comptime T: type, n_: Number(T)) T {
7878
7979 // Infinity and range error
8080 if (n.exponent > max_exp) {
81 return math.inf(T);
81 return if (n.negative) -math.inf(T) else math.inf(T);
8282 }
8383
8484 var bits = n.mantissa & ((1 << mantissa_bits) - 1);