aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-10-24 21:45:00 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-10-24 21:57:58 -0400
commit73fe5f63c6acc1b2e6fec51da545178ffd12180e (patch)
treefcb9d80ac056a2e81efb6e31915ee94866dea1b1 /std
parent1e784839f1b6ac116f7cae35fa4a8069902283b6 (diff)
downloadzig-73fe5f63c6acc1b2e6fec51da545178ffd12180e.tar.gz
zig-73fe5f63c6acc1b2e6fec51da545178ffd12180e.zip
add some sanity tests for float printing
Diffstat (limited to 'std')
-rw-r--r--std/fmt/index.zig32
1 files changed, 32 insertions, 0 deletions
diff --git a/std/fmt/index.zig b/std/fmt/index.zig
index 0fece54b4c..56b9a2e960 100644
--- a/std/fmt/index.zig
+++ b/std/fmt/index.zig
@@ -531,6 +531,38 @@ test "fmt.format" {
const result = bufPrint(buf1[0..], "u3: {}\n", value);
assert(mem.eql(u8, result, "u3: 5\n"));
}
+
+ // TODO get these tests passing in release modes
+ // https://github.com/zig-lang/zig/issues/564
+ if (builtin.mode == builtin.Mode.Debug) {
+ {
+ var buf1: [32]u8 = undefined;
+ const value: f32 = 12.34;
+ const result = bufPrint(buf1[0..], "f32: {}\n", value);
+ assert(mem.eql(u8, result, "f32: 1.23400001e1\n"));
+ }
+ {
+ var buf1: [32]u8 = undefined;
+ const value: f64 = -12.34e10;
+ const result = bufPrint(buf1[0..], "f64: {}\n", value);
+ assert(mem.eql(u8, result, "f64: -1.234e11\n"));
+ }
+ {
+ var buf1: [32]u8 = undefined;
+ const result = bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);
+ assert(mem.eql(u8, result, "f64: NaN\n"));
+ }
+ {
+ var buf1: [32]u8 = undefined;
+ const result = bufPrint(buf1[0..], "f64: {}\n", math.inf_f64);
+ assert(mem.eql(u8, result, "f64: Infinity\n"));
+ }
+ {
+ var buf1: [32]u8 = undefined;
+ const result = bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64);
+ assert(mem.eql(u8, result, "f64: -Infinity\n"));
+ }
+ }
}
pub fn trim(buf: []const u8) -> []const u8 {