Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/std/fmt/parse_float.zig
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ test "hex.special" {
try testing.expect(math.isPositiveInf(try parseFloat(f32, "iNf")));
try testing.expect(math.isPositiveInf(try parseFloat(f32, "+Inf")));
try testing.expect(math.isNegativeInf(try parseFloat(f32, "-iNf")));

try testing.expect(math.isPositiveInf(try parseFloat(f32, "0x9999p9999")));
try testing.expect(math.isNegativeInf(try parseFloat(f32, "-0x9999p9999")));
}

test "hex.zero" {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/fmt/parse_float/convert_hex.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn convertHex(comptime T: type, n_: Number(T)) T {

// Infinity and range error
if (n.exponent > max_exp) {
return math.inf(T);
return if (n.negative) -math.inf(T) else math.inf(T);
}

var bits = n.mantissa & ((1 << mantissa_bits) - 1);
Expand Down
Loading