From 02209d8a5f7b26d503ca5c3a73219fa8839243f6 Mon Sep 17 00:00:00 2001 From: Marc Tiehuis Date: Tue, 3 May 2022 19:04:16 +1200 Subject: [PATCH] fix aarch64 f16 nan parse test failure --- lib/std/fmt/parse_float/parse.zig | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/std/fmt/parse_float/parse.zig b/lib/std/fmt/parse_float/parse.zig index 104052c3b3..3b757c7c41 100644 --- a/lib/std/fmt/parse_float/parse.zig +++ b/lib/std/fmt/parse_float/parse.zig @@ -240,14 +240,15 @@ pub fn parseNumber(comptime T: type, s: []const u8, negative: bool) ?Number(T) { return null; } -fn parsePartialInfOrNan(comptime T: type, s: []const u8, n: *usize) ?T { +fn parsePartialInfOrNan(comptime T: type, s: []const u8, negative: bool, n: *usize) ?T { // inf/infinity; infxxx should only consume inf. if (std.ascii.startsWithIgnoreCase(s, "inf")) { n.* = 3; if (std.ascii.startsWithIgnoreCase(s[3..], "inity")) { n.* = 8; } - return std.math.inf(T); + + return if (!negative) std.math.inf(T) else -std.math.inf(T); } if (std.ascii.startsWithIgnoreCase(s, "nan")) { @@ -260,11 +261,8 @@ fn parsePartialInfOrNan(comptime T: type, s: []const u8, n: *usize) ?T { pub fn parseInfOrNan(comptime T: type, s: []const u8, negative: bool) ?T { var consumed: usize = 0; - if (parsePartialInfOrNan(T, s, &consumed)) |special| { + if (parsePartialInfOrNan(T, s, negative, &consumed)) |special| { if (s.len == consumed) { - if (negative) { - return -1 * special; - } return special; } }