diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-07-10 03:06:05 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-10 03:06:05 -0400 |
| commit | b88151e0e1553607cbebc197e1111ec4bf53a595 (patch) | |
| tree | cd4f57feae521500fe4eb99a98a798241256d341 /lib/std/fmt/parse_float.zig | |
| parent | 3f11d1d56d9747de974b00eab1c880bea7972c01 (diff) | |
| parent | f9bf4889264aee387639bb8a35fdf594236b1283 (diff) | |
| download | zig-b88151e0e1553607cbebc197e1111ec4bf53a595.tar.gz zig-b88151e0e1553607cbebc197e1111ec4bf53a595.zip | |
Merge pull request #12001 from ziglang/llvm14
Upgrade to LLVM 14
Diffstat (limited to 'lib/std/fmt/parse_float.zig')
| -rw-r--r-- | lib/std/fmt/parse_float.zig | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig index 3013ca7865..2f30c30f23 100644 --- a/lib/std/fmt/parse_float.zig +++ b/lib/std/fmt/parse_float.zig @@ -1,6 +1,7 @@ pub const parseFloat = @import("parse_float/parse_float.zig").parseFloat; pub const ParseFloatError = @import("parse_float/parse_float.zig").ParseFloatError; +const builtin = @import("builtin"); const std = @import("std"); const math = std.math; const testing = std.testing; @@ -14,8 +15,6 @@ const epsilon = 1e-7; test "fmt.parseFloat" { inline for ([_]type{ f16, f32, f64, f128 }) |T| { - const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); - try testing.expectError(error.InvalidCharacter, parseFloat(T, "")); try testing.expectError(error.InvalidCharacter, parseFloat(T, " 1")); try testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc")); @@ -40,10 +39,6 @@ test "fmt.parseFloat" { try expectEqual(try parseFloat(T, "1e-5000"), 0); try expectEqual(try parseFloat(T, "1e+5000"), std.math.inf(T)); - try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T))); - try expectEqual(try parseFloat(T, "inF"), std.math.inf(T)); - try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T)); - try expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T)); try expect(approxEqAbs(T, try parseFloat(T, "0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0"), @as(T, 123456.789000e10), epsilon)); @@ -74,6 +69,23 @@ test "fmt.parseFloat" { } } +test "fmt.parseFloat nan and inf" { + if ((builtin.zig_backend == .stage1 or builtin.zig_backend == .stage2_llvm) and + builtin.cpu.arch == .aarch64) + { + // https://github.com/ziglang/zig/issues/12027 + return error.SkipZigTest; + } + + inline for ([_]type{ f16, f32, f64, f128 }) |T| { + const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); + + try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T))); + try expectEqual(try parseFloat(T, "inF"), std.math.inf(T)); + try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T)); + } +} + test "fmt.parseFloat #11169" { try expectEqual(try parseFloat(f128, "9007199254740993.0"), 9007199254740993.0); } |
